#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< vector<int> > > Z_edge;
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_edge.push_back( vector< vector<int> >(N, vector<int>(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_edge[q][A].push_back(B);
Z_edge[q][B].push_back(A);
if((int)Z_edge[q][A].size() > 2 || (int)Z_edge[q][B].size() > 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 |
2 ms |
844 KB |
Output is correct |
2 |
Runtime error |
147 ms |
262148 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
147 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
844 KB |
Output is correct |
2 |
Runtime error |
147 ms |
262148 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
844 KB |
Output is correct |
2 |
Runtime error |
147 ms |
262148 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
844 KB |
Output is correct |
2 |
Runtime error |
147 ms |
262148 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |