#include <iostream>
#include <vector>
using namespace std;
struct disjoint_set
{
int S;
vector<int> parent;
vector<int> subtree;
disjoint_set()
{
;
}
disjoint_set(int s)
{
S = s;
parent = vector<int>(S);
subtree = vector<int>(S);
for(int i = 0; i < S; i++)
{
parent[i] = i;
subtree[i] = 1;
}
}
int root(int u)
{
int v = u;
while(parent[v] != v) v = parent[v];
parent[u] = v;
return v;
}
bool connected(int u, int v)
{
return root(u) == root(v);
}
void join(int u, int v)
{
u = root(u);
v = root(v);
if(u == v) return;
if(subtree[u] < subtree[v]) swap(u, v);
subtree[u] += subtree[v];
parent[v] = u;
}
};
const int X = 0;
const int Y = 1;
const int Z = 2;
int state = Z;
int N;
vector<int> Z_critical;
vector< vector<int> > Z_degree;
vector<disjoint_set> DSU;
vector<bool> good;
void Init(int N_)
{
N = N_;
for(int i = 0; i < N; i++)
{
Z_critical.push_back(i);
Z_degree.push_back(vector<int>(N, 0));
DSU.push_back(disjoint_set(N));
good.push_back(1);
}
}
void Link(int A, int B)
{
if(state == Z)
{
for(int q = 0; q < (int)Z_critical.size(); q++)
{
int z = Z_critical[q];
if(A == z || B == z)
{
continue;
}
if(DSU[q].connected(A, B))
{
good[q] = 0;
}
Z_degree[q][A]++;
Z_degree[q][B]++;
if(Z_degree[q][A] > 2 || Z_degree[q][B] > 2)
good[q] = 0;
DSU[q].join(A, B);
}
}
}
int CountCritical()
{
int res = 0;
for(int i = 0; i < N; i++)
{
res += good[i];
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
3641 ms |
206548 KB |
Output is correct |
3 |
Runtime error |
138 ms |
262148 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
132 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
3641 ms |
206548 KB |
Output is correct |
3 |
Runtime error |
138 ms |
262148 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
3641 ms |
206548 KB |
Output is correct |
3 |
Runtime error |
138 ms |
262148 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
3641 ms |
206548 KB |
Output is correct |
3 |
Runtime error |
138 ms |
262148 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |