#include <iostream>
#include <map>
#include <vector>
#include <queue>
#define ll long long
using namespace std;
map <ll, ll> mp;
bool ok;
ll visited[1000000], cur;
vector <ll> adj[1000000], V, U;
queue <ll> Q;
ll n, x, y, z, tot, P[1000000], cyc[1000000], deg[1000000];
ll dsu(ll u) {
if (P[u] == u) return u;
else return P[u] = dsu(P[u]);
}
void Init(int N_) {
ok = 0;
n = N_;
tot = 0;
mp.clear();
for (int i=0; i<n; ++i) {
adj[i].clear();
P[i] = i;
++mp[i];
}
}
void dfs(ll u, ll p) {
visited[u] = cur;
V.push_back(u);
for (auto v : adj[u]) {
if (visited[v] != cur) dfs(v, u);
else if (v != p) {
U.clear();
for (int i=V.size()-1; i>=0; --i) {
//cout << V[i] << "*";
if (mp.count(V[i])) U.push_back(V[i]);
if (V[i] == v) break;
}
//cout << endl;
mp.clear();
for (auto u : U) ++mp[u];
}
}
visited[u] = -1;
V.pop_back();
}
void relabel(ll u, ll p, ll w) {
P[u] = w;
visited[u] = cur;
for (auto v : adj[u]) {
if (visited[v] != cur && v != z) {
relabel(v, u, w);
}
}
}
void Link(int A, int B) {
if (mp.empty()) return;
else if (ok) {
if (A == z || B == z) return;
if (deg[A] == 2 || deg[B] == 2) {
mp.clear();
return;
}
++deg[A], ++deg[B];
x = dsu(A), y = dsu(B);
if (x == y) mp.clear();
P[x] = y;
return;
}
++deg[A], ++deg[B];
adj[A].push_back(B);
adj[B].push_back(A);
x = dsu(A), y = dsu(B);
if (x == y) {
++cyc[x];
if (cyc[x] <= 2) {
V.clear();
++cur;
dfs(A, -1);
}
else ok = 1;
}
else {
P[x] = y;
if (cyc[x] && cyc[y]) {
mp.clear();
return;
}
cyc[y] += cyc[x];
}
//cout << A << " " << B << " " << tot << endl;
if (deg[A] > 3) {
if (mp.count(A)) {
mp.clear();
++mp[A];
}
else mp.clear();
}
else if (deg[A] == 3) {
V.clear();
if (mp.count(A)) V.push_back(A);
for (auto v : adj[A]) {
if (mp.count(v)) V.push_back(v);
}
mp.clear();
for (auto u : V) ++mp[u];
}
if (deg[B] > 3) {
if (mp.count(B)) {
mp.clear();
++mp[B];
}
else mp.clear();
}
else if (deg[B] == 3) {
V.clear();
if (mp.count(B)) V.push_back(B);
for (auto v : adj[B]) {
if (mp.count(v)) V.push_back(v);
}
mp.clear();
for (auto u : V) ++mp[u];
}
if (ok) {
if (mp.size() > 1) {
mp.clear();
return;
}
for (auto [x, y] : mp) {
z = x;
for (auto v : adj[x]) {
--deg[v];
}
}
++cur;
tot = 0;
for (int i=0; i<n; ++i) {
if (i == z) continue;
if (deg[i] <= 1) {
Q.push(i);
visited[i] = cur;
}
else if (deg[i] > 2) {
mp.clear();
return;
}
}
while (!Q.empty()) {
auto u = Q.front();
Q.pop();
++tot;
for (auto v : adj[u]) {
if (v == z) continue;
if (visited[v] != cur) {
visited[v] = cur;
Q.push(v);
}
}
}
if (tot != n-1) mp.clear();
for (int i=0; i<n; ++i) {
if (i == z) continue;
if (deg[i] <= 1) {
++cur;
relabel(i, -1, i);
}
}
}
}
int CountCritical() {
return mp.size();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
26968 KB |
Output is correct |
2 |
Correct |
4 ms |
27484 KB |
Output is correct |
3 |
Correct |
5 ms |
27480 KB |
Output is correct |
4 |
Correct |
4 ms |
27228 KB |
Output is correct |
5 |
Correct |
4 ms |
27484 KB |
Output is correct |
6 |
Correct |
6 ms |
28252 KB |
Output is correct |
7 |
Correct |
4 ms |
27484 KB |
Output is correct |
8 |
Correct |
4 ms |
27484 KB |
Output is correct |
9 |
Correct |
4 ms |
27484 KB |
Output is correct |
10 |
Correct |
5 ms |
27484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
88240 KB |
Output is correct |
2 |
Correct |
561 ms |
109908 KB |
Output is correct |
3 |
Correct |
266 ms |
110420 KB |
Output is correct |
4 |
Correct |
672 ms |
144992 KB |
Output is correct |
5 |
Correct |
717 ms |
152124 KB |
Output is correct |
6 |
Correct |
2062 ms |
218344 KB |
Output is correct |
7 |
Correct |
265 ms |
111184 KB |
Output is correct |
8 |
Correct |
643 ms |
132688 KB |
Output is correct |
9 |
Correct |
672 ms |
140624 KB |
Output is correct |
10 |
Correct |
557 ms |
148048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
26968 KB |
Output is correct |
2 |
Correct |
4 ms |
27484 KB |
Output is correct |
3 |
Correct |
5 ms |
27480 KB |
Output is correct |
4 |
Correct |
4 ms |
27228 KB |
Output is correct |
5 |
Correct |
4 ms |
27484 KB |
Output is correct |
6 |
Correct |
6 ms |
28252 KB |
Output is correct |
7 |
Correct |
4 ms |
27484 KB |
Output is correct |
8 |
Correct |
4 ms |
27484 KB |
Output is correct |
9 |
Correct |
4 ms |
27484 KB |
Output is correct |
10 |
Correct |
5 ms |
27484 KB |
Output is correct |
11 |
Correct |
5 ms |
27484 KB |
Output is correct |
12 |
Correct |
8 ms |
28220 KB |
Output is correct |
13 |
Correct |
6 ms |
27972 KB |
Output is correct |
14 |
Correct |
6 ms |
27980 KB |
Output is correct |
15 |
Correct |
6 ms |
28764 KB |
Output is correct |
16 |
Correct |
7 ms |
28252 KB |
Output is correct |
17 |
Correct |
5 ms |
27996 KB |
Output is correct |
18 |
Correct |
7 ms |
28764 KB |
Output is correct |
19 |
Correct |
6 ms |
28252 KB |
Output is correct |
20 |
Correct |
6 ms |
28128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
26968 KB |
Output is correct |
2 |
Correct |
4 ms |
27484 KB |
Output is correct |
3 |
Correct |
5 ms |
27480 KB |
Output is correct |
4 |
Correct |
4 ms |
27228 KB |
Output is correct |
5 |
Correct |
4 ms |
27484 KB |
Output is correct |
6 |
Correct |
6 ms |
28252 KB |
Output is correct |
7 |
Correct |
4 ms |
27484 KB |
Output is correct |
8 |
Correct |
4 ms |
27484 KB |
Output is correct |
9 |
Correct |
4 ms |
27484 KB |
Output is correct |
10 |
Correct |
5 ms |
27484 KB |
Output is correct |
11 |
Correct |
5 ms |
27484 KB |
Output is correct |
12 |
Correct |
8 ms |
28220 KB |
Output is correct |
13 |
Correct |
6 ms |
27972 KB |
Output is correct |
14 |
Correct |
6 ms |
27980 KB |
Output is correct |
15 |
Correct |
6 ms |
28764 KB |
Output is correct |
16 |
Correct |
7 ms |
28252 KB |
Output is correct |
17 |
Correct |
5 ms |
27996 KB |
Output is correct |
18 |
Correct |
7 ms |
28764 KB |
Output is correct |
19 |
Correct |
6 ms |
28252 KB |
Output is correct |
20 |
Correct |
6 ms |
28128 KB |
Output is correct |
21 |
Correct |
19 ms |
34140 KB |
Output is correct |
22 |
Correct |
28 ms |
36948 KB |
Output is correct |
23 |
Correct |
33 ms |
38996 KB |
Output is correct |
24 |
Correct |
30 ms |
36956 KB |
Output is correct |
25 |
Correct |
22 ms |
36948 KB |
Output is correct |
26 |
Correct |
32 ms |
37492 KB |
Output is correct |
27 |
Correct |
34 ms |
40540 KB |
Output is correct |
28 |
Correct |
25 ms |
38748 KB |
Output is correct |
29 |
Correct |
33 ms |
37332 KB |
Output is correct |
30 |
Correct |
55 ms |
42580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
26968 KB |
Output is correct |
2 |
Correct |
4 ms |
27484 KB |
Output is correct |
3 |
Correct |
5 ms |
27480 KB |
Output is correct |
4 |
Correct |
4 ms |
27228 KB |
Output is correct |
5 |
Correct |
4 ms |
27484 KB |
Output is correct |
6 |
Correct |
6 ms |
28252 KB |
Output is correct |
7 |
Correct |
4 ms |
27484 KB |
Output is correct |
8 |
Correct |
4 ms |
27484 KB |
Output is correct |
9 |
Correct |
4 ms |
27484 KB |
Output is correct |
10 |
Correct |
5 ms |
27484 KB |
Output is correct |
11 |
Correct |
262 ms |
88240 KB |
Output is correct |
12 |
Correct |
561 ms |
109908 KB |
Output is correct |
13 |
Correct |
266 ms |
110420 KB |
Output is correct |
14 |
Correct |
672 ms |
144992 KB |
Output is correct |
15 |
Correct |
717 ms |
152124 KB |
Output is correct |
16 |
Correct |
2062 ms |
218344 KB |
Output is correct |
17 |
Correct |
265 ms |
111184 KB |
Output is correct |
18 |
Correct |
643 ms |
132688 KB |
Output is correct |
19 |
Correct |
672 ms |
140624 KB |
Output is correct |
20 |
Correct |
557 ms |
148048 KB |
Output is correct |
21 |
Correct |
5 ms |
27484 KB |
Output is correct |
22 |
Correct |
8 ms |
28220 KB |
Output is correct |
23 |
Correct |
6 ms |
27972 KB |
Output is correct |
24 |
Correct |
6 ms |
27980 KB |
Output is correct |
25 |
Correct |
6 ms |
28764 KB |
Output is correct |
26 |
Correct |
7 ms |
28252 KB |
Output is correct |
27 |
Correct |
5 ms |
27996 KB |
Output is correct |
28 |
Correct |
7 ms |
28764 KB |
Output is correct |
29 |
Correct |
6 ms |
28252 KB |
Output is correct |
30 |
Correct |
6 ms |
28128 KB |
Output is correct |
31 |
Correct |
19 ms |
34140 KB |
Output is correct |
32 |
Correct |
28 ms |
36948 KB |
Output is correct |
33 |
Correct |
33 ms |
38996 KB |
Output is correct |
34 |
Correct |
30 ms |
36956 KB |
Output is correct |
35 |
Correct |
22 ms |
36948 KB |
Output is correct |
36 |
Correct |
32 ms |
37492 KB |
Output is correct |
37 |
Correct |
34 ms |
40540 KB |
Output is correct |
38 |
Correct |
25 ms |
38748 KB |
Output is correct |
39 |
Correct |
33 ms |
37332 KB |
Output is correct |
40 |
Correct |
55 ms |
42580 KB |
Output is correct |
41 |
Correct |
164 ms |
82804 KB |
Output is correct |
42 |
Correct |
391 ms |
118396 KB |
Output is correct |
43 |
Correct |
241 ms |
117588 KB |
Output is correct |
44 |
Correct |
252 ms |
118872 KB |
Output is correct |
45 |
Correct |
341 ms |
136960 KB |
Output is correct |
46 |
Correct |
443 ms |
136732 KB |
Output is correct |
47 |
Correct |
1153 ms |
189364 KB |
Output is correct |
48 |
Correct |
253 ms |
118972 KB |
Output is correct |
49 |
Correct |
504 ms |
146256 KB |
Output is correct |
50 |
Correct |
506 ms |
144980 KB |
Output is correct |
51 |
Correct |
258 ms |
106068 KB |
Output is correct |
52 |
Correct |
242 ms |
102848 KB |
Output is correct |
53 |
Correct |
249 ms |
117464 KB |
Output is correct |
54 |
Correct |
536 ms |
127064 KB |
Output is correct |
55 |
Correct |
603 ms |
115548 KB |
Output is correct |