#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) {
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 |
5 ms |
27096 KB |
Output is correct |
2 |
Correct |
4 ms |
27480 KB |
Output is correct |
3 |
Correct |
6 ms |
27740 KB |
Output is correct |
4 |
Correct |
3 ms |
27228 KB |
Output is correct |
5 |
Correct |
5 ms |
27736 KB |
Output is correct |
6 |
Correct |
6 ms |
28248 KB |
Output is correct |
7 |
Correct |
4 ms |
27484 KB |
Output is correct |
8 |
Correct |
4 ms |
27408 KB |
Output is correct |
9 |
Correct |
5 ms |
27740 KB |
Output is correct |
10 |
Correct |
4 ms |
27740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
266 ms |
95180 KB |
Output is correct |
2 |
Correct |
544 ms |
120600 KB |
Output is correct |
3 |
Correct |
321 ms |
123216 KB |
Output is correct |
4 |
Correct |
672 ms |
158288 KB |
Output is correct |
5 |
Correct |
743 ms |
165500 KB |
Output is correct |
6 |
Correct |
1765 ms |
232928 KB |
Output is correct |
7 |
Correct |
267 ms |
122984 KB |
Output is correct |
8 |
Correct |
643 ms |
145304 KB |
Output is correct |
9 |
Correct |
687 ms |
153920 KB |
Output is correct |
10 |
Correct |
516 ms |
160280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
27096 KB |
Output is correct |
2 |
Correct |
4 ms |
27480 KB |
Output is correct |
3 |
Correct |
6 ms |
27740 KB |
Output is correct |
4 |
Correct |
3 ms |
27228 KB |
Output is correct |
5 |
Correct |
5 ms |
27736 KB |
Output is correct |
6 |
Correct |
6 ms |
28248 KB |
Output is correct |
7 |
Correct |
4 ms |
27484 KB |
Output is correct |
8 |
Correct |
4 ms |
27408 KB |
Output is correct |
9 |
Correct |
5 ms |
27740 KB |
Output is correct |
10 |
Correct |
4 ms |
27740 KB |
Output is correct |
11 |
Correct |
5 ms |
27736 KB |
Output is correct |
12 |
Correct |
6 ms |
28252 KB |
Output is correct |
13 |
Correct |
6 ms |
28128 KB |
Output is correct |
14 |
Incorrect |
6 ms |
27996 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
27096 KB |
Output is correct |
2 |
Correct |
4 ms |
27480 KB |
Output is correct |
3 |
Correct |
6 ms |
27740 KB |
Output is correct |
4 |
Correct |
3 ms |
27228 KB |
Output is correct |
5 |
Correct |
5 ms |
27736 KB |
Output is correct |
6 |
Correct |
6 ms |
28248 KB |
Output is correct |
7 |
Correct |
4 ms |
27484 KB |
Output is correct |
8 |
Correct |
4 ms |
27408 KB |
Output is correct |
9 |
Correct |
5 ms |
27740 KB |
Output is correct |
10 |
Correct |
4 ms |
27740 KB |
Output is correct |
11 |
Correct |
5 ms |
27736 KB |
Output is correct |
12 |
Correct |
6 ms |
28252 KB |
Output is correct |
13 |
Correct |
6 ms |
28128 KB |
Output is correct |
14 |
Incorrect |
6 ms |
27996 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
27096 KB |
Output is correct |
2 |
Correct |
4 ms |
27480 KB |
Output is correct |
3 |
Correct |
6 ms |
27740 KB |
Output is correct |
4 |
Correct |
3 ms |
27228 KB |
Output is correct |
5 |
Correct |
5 ms |
27736 KB |
Output is correct |
6 |
Correct |
6 ms |
28248 KB |
Output is correct |
7 |
Correct |
4 ms |
27484 KB |
Output is correct |
8 |
Correct |
4 ms |
27408 KB |
Output is correct |
9 |
Correct |
5 ms |
27740 KB |
Output is correct |
10 |
Correct |
4 ms |
27740 KB |
Output is correct |
11 |
Correct |
266 ms |
95180 KB |
Output is correct |
12 |
Correct |
544 ms |
120600 KB |
Output is correct |
13 |
Correct |
321 ms |
123216 KB |
Output is correct |
14 |
Correct |
672 ms |
158288 KB |
Output is correct |
15 |
Correct |
743 ms |
165500 KB |
Output is correct |
16 |
Correct |
1765 ms |
232928 KB |
Output is correct |
17 |
Correct |
267 ms |
122984 KB |
Output is correct |
18 |
Correct |
643 ms |
145304 KB |
Output is correct |
19 |
Correct |
687 ms |
153920 KB |
Output is correct |
20 |
Correct |
516 ms |
160280 KB |
Output is correct |
21 |
Correct |
5 ms |
27736 KB |
Output is correct |
22 |
Correct |
6 ms |
28252 KB |
Output is correct |
23 |
Correct |
6 ms |
28128 KB |
Output is correct |
24 |
Incorrect |
6 ms |
27996 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |