///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define append push_back
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define MAXN 1000001
int n,x;
int e[MAXN];
int par[MAXN];
int vis[MAXN];
vector<int> a[MAXN];
void dfs(int v,int u,vector<int>& vec){
vis[v]=1;
vec.append(v);
for(auto& i:a[v])
if(!vis[i])
dfs(i,u,vec);
if(vec.back()!=u) vec.pop_back();
}
int root(int v){
if(par[v]==v) return v;
par[v]=root(par[v]);
return par[v];
}
void join(int v,int u){
par[root(u)]=root(v);
}
bool same(int v,int u){
return (root(v)==root(u));
}
void Init(int u){
n=x=u;
for(int i=0;i<n;i++){
par[i]=i;
e[i]=1;
}
}
void Link(int v, int u){
if(!x) return;
if(a[v].size()==2 && a[u].size()==2){
for(int i=0;i<n;i++)
if(i!=v && i!=u)
e[i]=0;
x=e[v]+e[u];
join(v,u);
a[v].append(u);
a[u].append(v);
}
else if(a[v].size()==3 || a[u].size()==3){
if(a[v].size()!=3) swap(v,u);
for(int i=0;i<n;i++)
if(i!=v) e[i]=0;
x=e[v];
join(v,u);
a[v].append(u);
a[u].append(v);
}
else if(a[v].size()==2 || a[u].size()==2){
if(a[v].size()!=2) swap(v,u);
map<int,int> z;
a[v].append(u);
a[u].append(v);
join(v,u);
z[v]=1;
for(auto& i:a[v]) z[i]=1;
for(int i=0;i<n;i++)
if(!z[i])
e[i]=0;
x=0;
for(auto& i:z)
x+=e[i.ff];
}
else if(a[v].size()==1 && a[u].size()==1 && same(v,u)){
vector<int> vec;
for(int i=0;i<n;i++) vis[i]=0;
dfs(v,u,vec);
map<int,int> z;
a[v].append(u);
a[u].append(v);
join(v,u);
for(auto& i:vec)
z[i]=1;
for(int i=x=0;i<n;i++)
if(!z[i])
e[i]=0;
for(auto& i:z)
x+=e[i.ff];
}
else{
a[v].append(u);
a[u].append(v);
join(v,u);
}
}
int CountCritical(){
return x;;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
29276 KB |
Output is correct |
2 |
Correct |
9 ms |
29532 KB |
Output is correct |
3 |
Correct |
10 ms |
29568 KB |
Output is correct |
4 |
Correct |
8 ms |
29276 KB |
Output is correct |
5 |
Correct |
10 ms |
29732 KB |
Output is correct |
6 |
Correct |
10 ms |
30044 KB |
Output is correct |
7 |
Correct |
9 ms |
29532 KB |
Output is correct |
8 |
Correct |
10 ms |
29532 KB |
Output is correct |
9 |
Correct |
10 ms |
29600 KB |
Output is correct |
10 |
Correct |
10 ms |
29788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
211 ms |
56404 KB |
Output is correct |
2 |
Correct |
735 ms |
95824 KB |
Output is correct |
3 |
Correct |
554 ms |
93760 KB |
Output is correct |
4 |
Correct |
835 ms |
127428 KB |
Output is correct |
5 |
Correct |
893 ms |
128644 KB |
Output is correct |
6 |
Correct |
1477 ms |
157996 KB |
Output is correct |
7 |
Correct |
536 ms |
93228 KB |
Output is correct |
8 |
Correct |
1115 ms |
117408 KB |
Output is correct |
9 |
Correct |
1277 ms |
125048 KB |
Output is correct |
10 |
Correct |
840 ms |
125240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
29276 KB |
Output is correct |
2 |
Correct |
9 ms |
29532 KB |
Output is correct |
3 |
Correct |
10 ms |
29568 KB |
Output is correct |
4 |
Correct |
8 ms |
29276 KB |
Output is correct |
5 |
Correct |
10 ms |
29732 KB |
Output is correct |
6 |
Correct |
10 ms |
30044 KB |
Output is correct |
7 |
Correct |
9 ms |
29532 KB |
Output is correct |
8 |
Correct |
10 ms |
29532 KB |
Output is correct |
9 |
Correct |
10 ms |
29600 KB |
Output is correct |
10 |
Correct |
10 ms |
29788 KB |
Output is correct |
11 |
Correct |
10 ms |
29788 KB |
Output is correct |
12 |
Correct |
14 ms |
30044 KB |
Output is correct |
13 |
Correct |
16 ms |
30044 KB |
Output is correct |
14 |
Incorrect |
39 ms |
30040 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
29276 KB |
Output is correct |
2 |
Correct |
9 ms |
29532 KB |
Output is correct |
3 |
Correct |
10 ms |
29568 KB |
Output is correct |
4 |
Correct |
8 ms |
29276 KB |
Output is correct |
5 |
Correct |
10 ms |
29732 KB |
Output is correct |
6 |
Correct |
10 ms |
30044 KB |
Output is correct |
7 |
Correct |
9 ms |
29532 KB |
Output is correct |
8 |
Correct |
10 ms |
29532 KB |
Output is correct |
9 |
Correct |
10 ms |
29600 KB |
Output is correct |
10 |
Correct |
10 ms |
29788 KB |
Output is correct |
11 |
Correct |
10 ms |
29788 KB |
Output is correct |
12 |
Correct |
14 ms |
30044 KB |
Output is correct |
13 |
Correct |
16 ms |
30044 KB |
Output is correct |
14 |
Incorrect |
39 ms |
30040 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
29276 KB |
Output is correct |
2 |
Correct |
9 ms |
29532 KB |
Output is correct |
3 |
Correct |
10 ms |
29568 KB |
Output is correct |
4 |
Correct |
8 ms |
29276 KB |
Output is correct |
5 |
Correct |
10 ms |
29732 KB |
Output is correct |
6 |
Correct |
10 ms |
30044 KB |
Output is correct |
7 |
Correct |
9 ms |
29532 KB |
Output is correct |
8 |
Correct |
10 ms |
29532 KB |
Output is correct |
9 |
Correct |
10 ms |
29600 KB |
Output is correct |
10 |
Correct |
10 ms |
29788 KB |
Output is correct |
11 |
Correct |
211 ms |
56404 KB |
Output is correct |
12 |
Correct |
735 ms |
95824 KB |
Output is correct |
13 |
Correct |
554 ms |
93760 KB |
Output is correct |
14 |
Correct |
835 ms |
127428 KB |
Output is correct |
15 |
Correct |
893 ms |
128644 KB |
Output is correct |
16 |
Correct |
1477 ms |
157996 KB |
Output is correct |
17 |
Correct |
536 ms |
93228 KB |
Output is correct |
18 |
Correct |
1115 ms |
117408 KB |
Output is correct |
19 |
Correct |
1277 ms |
125048 KB |
Output is correct |
20 |
Correct |
840 ms |
125240 KB |
Output is correct |
21 |
Correct |
10 ms |
29788 KB |
Output is correct |
22 |
Correct |
14 ms |
30044 KB |
Output is correct |
23 |
Correct |
16 ms |
30044 KB |
Output is correct |
24 |
Incorrect |
39 ms |
30040 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |