CF353E.Antichain
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a directed acyclic graph G, consisting of n vertexes, numbered from 0 to n - 1. The graph contains n edges numbered from 0 to n - 1. An edge with number i connects vertexes i and (i + 1) mod n, and it can be directed in either direction (from i to (i + 1) mod n, or vise versa).
Operation x mod y means taking the remainder after dividing number x by number y.
Let's call two vertexes u and v in graph G comparable if the graph contains a path either from u to v or from v to u. We'll assume that an antichain is a set of vertexes of graph G, where any two distinct vertexes are not comparable. The size of an antichain is the number of vertexes in the corresponding set. An antichain is maximum if the graph doesn't have antichains of a larger size.
Your task is to find the size of the maximum antichain in graph G.
你有一个有向无环图 G,包含 n 个顶点,编号从 0 到 n−1。该图包含 n 条边,编号从 0 到 n−1。编号为 i 的边连接顶点 i 和 (i+1)modn,且该边可以是任意方向(即从 i 指向 (i+1)modn,或反之)。
运算 xmody 表示 x 除以 y 后所得的余数。
若图 G 中存在一条从 u 到 v 的路径,或存在一条从 v 到 u 的路径,则称图 G 中的两个顶点 u 和 v 是可比较的。我们定义一个反链(antichain) 为图 G 的一个顶点集合,其中任意两个不同的顶点均不可比较。反链的大小即为其所含顶点的数目。若图 G 中不存在大小更大的反链,则称该反链为最大反链。
你的任务是求出图 G 中最大反链的大小。
输入格式
The first line contains the sequence of characters _s_0_s_1... s__n - 1 (2 ≤ n ≤ 106), consisting of numbers zero and one. The length of the line (number n) corresponds to the number of vertexes and edges in graph G. If character s__i (i ≥ 0) equals 0, then the edge between vertexes i and (i + 1) mod n is directed from the i-th vertex to the (i + 1) mod n-th one, otherwise — to the opposite point.
It is guaranteed that the given graph is acyclic.
第一行包含一个由数字 0 和 1 组成的字符序列 s0s1…sn−1(其中 2≤n≤106)。该字符串的长度(即 n)对应于图 G 的顶点数与边数。若字符 si(i≥0)等于 0,则顶点 i 与顶点 (i+1)modn 之间的边为从第 i 个顶点指向第 (i+1)modn 个顶点的有向边;否则,该边方向相反。
保证所给图 G 是无环的。
输出格式
Print a single integer — the size of the maximum antichain of graph G.
输出一个整数——图 G 的最大反链的大小。
输入输出样例
输入#1
001
输出#1
1
输入#2
110010
输出#2
3
说明/提示
Consider the first test sample. The graph's G edges are: 0 → 1, 1 → 2, 0 → 2. We can choose the set of vertexes [0] as the maximum antichain. We cannot choose an antichain of larger size.
考虑第一个测试样例。图 G 的边为:0→1、1→2、0→2。我们可以选择顶点集 {0} 作为最大反链。无法选择更大规模的反链。
输入解题思路,AI测评打分。不知道怎么写?