#include<cstdio>
#include<vector>
using namespace std;
const int SZ = 1000010;
int min(int a, int b) { return a < b ? a : b; }
int n;
int cycleNum;
vector<int>l[SZ];
typedef struct Graph {
int st[4], ts[3];
int p[SZ], sz[SZ], ln[SZ];
bool is3E[SZ], isCX[SZ];
int x;
void init() {
x = n;
st[0] = ts[0] = n;
st[1] = st[2] = st[3] = ts[1] = ts[2] = 0;
for (int i = 0; i < n; i++) {
p[i] = i;
sz[i] = 1;
ln[i] = 0;
is3E[i] = isCX[i] = false;
}
}
void init(int X) {
init();
x = X;
int i, a, b, c;
for (i = 0; i < n; i++) {
for (int e : l[i]) {
if (e > i) {
if (e == x || i == x) {
isCX[e + i - x] = true;
continue;
}
a = f(e), b = f(i);
if (a != b) {
p[b] = a;
ln[a] += ln[b];
sz[a] += sz[b];
}
ln[a]++;
}
}
c = gC(i);
st[min(c, 3)]++;
if (c > 2)is3E[f(i)] = true;
}
for (i = 0; i < n; i++) {
if (i == p[i])ts[gT(i)]++;
}
}
int f(int a) {
return a == p[a] ? a : p[a] = f(p[a]);
}
int gC(int A) {
if (A == x)return 0;
return l[A].size() - (isCX[A] ? 1 : 0);
}
void u(int A, int B) {
int a = f(A), b = f(B);
if (a != b) {
p[b] = a;
ts[gT(a)]--;
ts[gT(b)]--;
ln[a] += ln[b];
sz[a] += sz[b];
is3E[a] |= is3E[b];
}
else {
ts[gT(a)]--;
}
}
void Con(int A, int B) {
int a = f(A), c;
if (x == n)l[A].push_back(B);
c = gC(A);
st[min(c - 1, 3)]--;
st[min(c, 3)]++;
if (c >= 3)is3E[a] = true;
}
int gT(int a) {
if (is3E[a]) {
return 2;
}
else if (sz[a] == ln[a]) {
return 1;
}
else {
return 0;
}
}
void Link(int A, int B) {
if (A == x || B == x) {
isCX[A + B - x] = true;
return;
}
u(A, B);
Con(A, B);
Con(B, A);
int a = f(A);
ln[a]++;
ts[gT(a)]++;
}
bool isChain() {
return (ts[1] + ts[2] == 0);
}
}Graph;
Graph MG, GV[4];
int GS;
void Init(int N) {
cycleNum = n = N;
MG.init();
}
void Link(int A, int B) {
bool p = (MG.st[3] == 0);
MG.Link(A, B);
for (int i = 0; i < GS; i++) {
GV[i].Link(A, B);
}
if (MG.gT(MG.f(A)) == 1)cycleNum = MG.f(A);
if (MG.gT(MG.f(B)) == 1)cycleNum = MG.f(B);
if (p && MG.st[3]) {
int a = A;
if (l[A].size() < 3)a = B;
GS = l[a].size() + 1;
GV[l[a].size()].init(a);
for (int i = 0; i < l[a].size(); i++) {
GV[i].init(l[a][i]);
}
}
}
int CountCritical() {
if (MG.ts[2]) {
int r = 0;
for (int i = 0; i < GS; i++) {
if (GV[i].isChain())r++;
}
return r;
}
else if (MG.ts[1]) {
if (MG.ts[1] > 1)return 0;
return MG.sz[cycleNum];
}
else {
return n;
}
}
Compilation message
rings.cpp: In function 'void Link(int, int)':
rings.cpp:128:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
128 | for (int i = 0; i < l[a].size(); i++) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23884 KB |
Output is correct |
2 |
Correct |
19 ms |
24328 KB |
Output is correct |
3 |
Correct |
20 ms |
24524 KB |
Output is correct |
4 |
Correct |
15 ms |
23832 KB |
Output is correct |
5 |
Correct |
17 ms |
23884 KB |
Output is correct |
6 |
Correct |
17 ms |
24012 KB |
Output is correct |
7 |
Correct |
16 ms |
24256 KB |
Output is correct |
8 |
Correct |
17 ms |
24012 KB |
Output is correct |
9 |
Correct |
20 ms |
24508 KB |
Output is correct |
10 |
Correct |
18 ms |
24456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
499 ms |
47288 KB |
Output is correct |
2 |
Correct |
2373 ms |
103812 KB |
Output is correct |
3 |
Correct |
3708 ms |
119500 KB |
Output is correct |
4 |
Correct |
1250 ms |
68748 KB |
Output is correct |
5 |
Correct |
1212 ms |
68740 KB |
Output is correct |
6 |
Correct |
1167 ms |
67672 KB |
Output is correct |
7 |
Correct |
3393 ms |
119184 KB |
Output is correct |
8 |
Correct |
2403 ms |
117176 KB |
Output is correct |
9 |
Correct |
2401 ms |
123512 KB |
Output is correct |
10 |
Correct |
918 ms |
67652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23884 KB |
Output is correct |
2 |
Correct |
19 ms |
24328 KB |
Output is correct |
3 |
Correct |
20 ms |
24524 KB |
Output is correct |
4 |
Correct |
15 ms |
23832 KB |
Output is correct |
5 |
Correct |
17 ms |
23884 KB |
Output is correct |
6 |
Correct |
17 ms |
24012 KB |
Output is correct |
7 |
Correct |
16 ms |
24256 KB |
Output is correct |
8 |
Correct |
17 ms |
24012 KB |
Output is correct |
9 |
Correct |
20 ms |
24508 KB |
Output is correct |
10 |
Correct |
18 ms |
24456 KB |
Output is correct |
11 |
Correct |
18 ms |
24444 KB |
Output is correct |
12 |
Correct |
22 ms |
25008 KB |
Output is correct |
13 |
Correct |
23 ms |
24876 KB |
Output is correct |
14 |
Correct |
20 ms |
24780 KB |
Output is correct |
15 |
Correct |
21 ms |
25472 KB |
Output is correct |
16 |
Correct |
20 ms |
24244 KB |
Output is correct |
17 |
Correct |
23 ms |
24984 KB |
Output is correct |
18 |
Correct |
25 ms |
25676 KB |
Output is correct |
19 |
Correct |
19 ms |
24268 KB |
Output is correct |
20 |
Correct |
24 ms |
24940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23884 KB |
Output is correct |
2 |
Correct |
19 ms |
24328 KB |
Output is correct |
3 |
Correct |
20 ms |
24524 KB |
Output is correct |
4 |
Correct |
15 ms |
23832 KB |
Output is correct |
5 |
Correct |
17 ms |
23884 KB |
Output is correct |
6 |
Correct |
17 ms |
24012 KB |
Output is correct |
7 |
Correct |
16 ms |
24256 KB |
Output is correct |
8 |
Correct |
17 ms |
24012 KB |
Output is correct |
9 |
Correct |
20 ms |
24508 KB |
Output is correct |
10 |
Correct |
18 ms |
24456 KB |
Output is correct |
11 |
Correct |
18 ms |
24444 KB |
Output is correct |
12 |
Correct |
22 ms |
25008 KB |
Output is correct |
13 |
Correct |
23 ms |
24876 KB |
Output is correct |
14 |
Correct |
20 ms |
24780 KB |
Output is correct |
15 |
Correct |
21 ms |
25472 KB |
Output is correct |
16 |
Correct |
20 ms |
24244 KB |
Output is correct |
17 |
Correct |
23 ms |
24984 KB |
Output is correct |
18 |
Correct |
25 ms |
25676 KB |
Output is correct |
19 |
Correct |
19 ms |
24268 KB |
Output is correct |
20 |
Correct |
24 ms |
24940 KB |
Output is correct |
21 |
Correct |
32 ms |
25544 KB |
Output is correct |
22 |
Correct |
53 ms |
26552 KB |
Output is correct |
23 |
Correct |
54 ms |
27256 KB |
Output is correct |
24 |
Correct |
126 ms |
31880 KB |
Output is correct |
25 |
Correct |
41 ms |
31068 KB |
Output is correct |
26 |
Correct |
111 ms |
32636 KB |
Output is correct |
27 |
Correct |
76 ms |
27700 KB |
Output is correct |
28 |
Correct |
142 ms |
32720 KB |
Output is correct |
29 |
Correct |
92 ms |
32452 KB |
Output is correct |
30 |
Correct |
74 ms |
28288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23884 KB |
Output is correct |
2 |
Correct |
19 ms |
24328 KB |
Output is correct |
3 |
Correct |
20 ms |
24524 KB |
Output is correct |
4 |
Correct |
15 ms |
23832 KB |
Output is correct |
5 |
Correct |
17 ms |
23884 KB |
Output is correct |
6 |
Correct |
17 ms |
24012 KB |
Output is correct |
7 |
Correct |
16 ms |
24256 KB |
Output is correct |
8 |
Correct |
17 ms |
24012 KB |
Output is correct |
9 |
Correct |
20 ms |
24508 KB |
Output is correct |
10 |
Correct |
18 ms |
24456 KB |
Output is correct |
11 |
Correct |
499 ms |
47288 KB |
Output is correct |
12 |
Correct |
2373 ms |
103812 KB |
Output is correct |
13 |
Correct |
3708 ms |
119500 KB |
Output is correct |
14 |
Correct |
1250 ms |
68748 KB |
Output is correct |
15 |
Correct |
1212 ms |
68740 KB |
Output is correct |
16 |
Correct |
1167 ms |
67672 KB |
Output is correct |
17 |
Correct |
3393 ms |
119184 KB |
Output is correct |
18 |
Correct |
2403 ms |
117176 KB |
Output is correct |
19 |
Correct |
2401 ms |
123512 KB |
Output is correct |
20 |
Correct |
918 ms |
67652 KB |
Output is correct |
21 |
Correct |
18 ms |
24444 KB |
Output is correct |
22 |
Correct |
22 ms |
25008 KB |
Output is correct |
23 |
Correct |
23 ms |
24876 KB |
Output is correct |
24 |
Correct |
20 ms |
24780 KB |
Output is correct |
25 |
Correct |
21 ms |
25472 KB |
Output is correct |
26 |
Correct |
20 ms |
24244 KB |
Output is correct |
27 |
Correct |
23 ms |
24984 KB |
Output is correct |
28 |
Correct |
25 ms |
25676 KB |
Output is correct |
29 |
Correct |
19 ms |
24268 KB |
Output is correct |
30 |
Correct |
24 ms |
24940 KB |
Output is correct |
31 |
Correct |
32 ms |
25544 KB |
Output is correct |
32 |
Correct |
53 ms |
26552 KB |
Output is correct |
33 |
Correct |
54 ms |
27256 KB |
Output is correct |
34 |
Correct |
126 ms |
31880 KB |
Output is correct |
35 |
Correct |
41 ms |
31068 KB |
Output is correct |
36 |
Correct |
111 ms |
32636 KB |
Output is correct |
37 |
Correct |
76 ms |
27700 KB |
Output is correct |
38 |
Correct |
142 ms |
32720 KB |
Output is correct |
39 |
Correct |
92 ms |
32452 KB |
Output is correct |
40 |
Correct |
74 ms |
28288 KB |
Output is correct |
41 |
Correct |
241 ms |
39152 KB |
Output is correct |
42 |
Correct |
1084 ms |
97164 KB |
Output is correct |
43 |
Correct |
462 ms |
90844 KB |
Output is correct |
44 |
Correct |
2236 ms |
115400 KB |
Output is correct |
45 |
Correct |
2369 ms |
113104 KB |
Output is correct |
46 |
Correct |
861 ms |
61668 KB |
Output is correct |
47 |
Correct |
1012 ms |
62492 KB |
Output is correct |
48 |
Correct |
1212 ms |
108816 KB |
Output is correct |
49 |
Correct |
815 ms |
63036 KB |
Output is correct |
50 |
Correct |
820 ms |
62708 KB |
Output is correct |
51 |
Correct |
609 ms |
83268 KB |
Output is correct |
52 |
Correct |
1914 ms |
97208 KB |
Output is correct |
53 |
Correct |
1261 ms |
109260 KB |
Output is correct |
54 |
Correct |
2294 ms |
104544 KB |
Output is correct |
55 |
Correct |
2913 ms |
111996 KB |
Output is correct |