/* Arthur Conmy / arthurconmy */
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>
#include <deque>
#include <chrono>
using namespace std;
const int MAXN=1000001;
// GENERAL
int n;
vector<int> adj[MAXN];
int deg[MAXN];
int v_max=0;
int d_max=0;
// DSU
int link[MAXN];
int sz[MAXN];
int no_cycles=0;
int cycle_size=-1;
// DFS
bool vis[MAXN];
int cur_ignore=-1;
bool dfs(int b4, int u)
{
vis[u]=1;
for(auto v:adj[u])
{
if(v==cur_ignore) continue;
if(vis[v] && v!=b4) return false;
if(vis[v]) continue;
bool b = dfs(u,v);
if(!b) return false;
}
return true;
}
int emp(int a)
{
while(a!=link[a]) a=link[a];
return a;
}
void join(int a, int b)
{
a=emp(a);
b=emp(b);
if(a==b) return;
if(sz[a]<sz[b]) swap(a,b);
sz[a]+=sz[b];
link[b]=a;
}
void Init(int N)
{
n=N;
for(int i=0; i<n; i++)
{
link[i]=i;
sz[i]=1;
}
}
void Link(int A, int B)
{
adj[A].push_back(B);
adj[B].push_back(A);
deg[A]++;
deg[B]++;
if(deg[B]>deg[A]) swap(A,B);
if(deg[A] > d_max)
{
d_max=deg[A];
v_max=A;
}
if(emp(A)==emp(B))
{
no_cycles++;
cycle_size=sz[emp(A)];
}
join(A,B);
}
int CountCritical()
{
if(d_max < 2)
{
return n;
}
if(d_max == 2)
{
if(no_cycles==0) return n;
if(no_cycles>1) return 0;
return cycle_size;
}
vector<int> trying = {v_max};
if(d_max==3)
{
for(auto u:adj[v_max]) trying.push_back(u);
}
int no_that_work=0;
for(auto v:trying)
{
// cout << v << endl;
for(int i=0; i<n; i++) vis[i]=0;
bool works=1;
for(auto u:adj[v])
{
deg[u]--;
}
for(int i=1; i<MAXN; i++)
{
if(i==v) continue;
if(deg[i] > 2) works=0;
}
for(auto u:adj[v])
{
deg[u]++;
}
if(!works) continue;
// cout << works << endl;
cur_ignore = v;
for(int i=0; i<n; i++)
{
if(i==cur_ignore) continue;
if(vis[i]) continue;
bool b2 = dfs(-1,i);
// cout << v << " " << i << " " << b2 << endl;
if(!b2)
{
works=0;
break;
}
}
if(works) no_that_work++;
}
return no_that_work;
}
void thing()
{
cout << CountCritical() << endl;
}
// int main()
// {
// #ifdef ARTHUR_LOCAL
// ifstream cin("input.txt");
// #endif
// Init(7);
// Link(1,2);
// Link(2,3);
// Link(2,0);
// Link(0,5);
// Link(3,5);
// Link(3,4);
// thing();
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
23800 KB |
Output is correct |
2 |
Correct |
27 ms |
24056 KB |
Output is correct |
3 |
Correct |
28 ms |
24056 KB |
Output is correct |
4 |
Correct |
23 ms |
23800 KB |
Output is correct |
5 |
Correct |
24 ms |
23928 KB |
Output is correct |
6 |
Correct |
25 ms |
24056 KB |
Output is correct |
7 |
Correct |
28 ms |
23928 KB |
Output is correct |
8 |
Correct |
25 ms |
24056 KB |
Output is correct |
9 |
Correct |
30 ms |
24184 KB |
Output is correct |
10 |
Correct |
31 ms |
24184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
451 ms |
46384 KB |
Output is correct |
2 |
Correct |
1151 ms |
59416 KB |
Output is correct |
3 |
Correct |
1142 ms |
63856 KB |
Output is correct |
4 |
Correct |
1201 ms |
67176 KB |
Output is correct |
5 |
Correct |
1193 ms |
67044 KB |
Output is correct |
6 |
Correct |
1156 ms |
65912 KB |
Output is correct |
7 |
Correct |
1128 ms |
63516 KB |
Output is correct |
8 |
Correct |
1623 ms |
65500 KB |
Output is correct |
9 |
Correct |
1479 ms |
81908 KB |
Output is correct |
10 |
Correct |
878 ms |
77816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
23800 KB |
Output is correct |
2 |
Correct |
27 ms |
24056 KB |
Output is correct |
3 |
Correct |
28 ms |
24056 KB |
Output is correct |
4 |
Correct |
23 ms |
23800 KB |
Output is correct |
5 |
Correct |
24 ms |
23928 KB |
Output is correct |
6 |
Correct |
25 ms |
24056 KB |
Output is correct |
7 |
Correct |
28 ms |
23928 KB |
Output is correct |
8 |
Correct |
25 ms |
24056 KB |
Output is correct |
9 |
Correct |
30 ms |
24184 KB |
Output is correct |
10 |
Correct |
31 ms |
24184 KB |
Output is correct |
11 |
Correct |
127 ms |
24220 KB |
Output is correct |
12 |
Correct |
56 ms |
24500 KB |
Output is correct |
13 |
Correct |
174 ms |
24444 KB |
Output is correct |
14 |
Correct |
105 ms |
24312 KB |
Output is correct |
15 |
Correct |
129 ms |
24312 KB |
Output is correct |
16 |
Correct |
29 ms |
24440 KB |
Output is correct |
17 |
Correct |
328 ms |
24520 KB |
Output is correct |
18 |
Correct |
135 ms |
24696 KB |
Output is correct |
19 |
Correct |
30 ms |
24440 KB |
Output is correct |
20 |
Correct |
190 ms |
24568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
23800 KB |
Output is correct |
2 |
Correct |
27 ms |
24056 KB |
Output is correct |
3 |
Correct |
28 ms |
24056 KB |
Output is correct |
4 |
Correct |
23 ms |
23800 KB |
Output is correct |
5 |
Correct |
24 ms |
23928 KB |
Output is correct |
6 |
Correct |
25 ms |
24056 KB |
Output is correct |
7 |
Correct |
28 ms |
23928 KB |
Output is correct |
8 |
Correct |
25 ms |
24056 KB |
Output is correct |
9 |
Correct |
30 ms |
24184 KB |
Output is correct |
10 |
Correct |
31 ms |
24184 KB |
Output is correct |
11 |
Correct |
127 ms |
24220 KB |
Output is correct |
12 |
Correct |
56 ms |
24500 KB |
Output is correct |
13 |
Correct |
174 ms |
24444 KB |
Output is correct |
14 |
Correct |
105 ms |
24312 KB |
Output is correct |
15 |
Correct |
129 ms |
24312 KB |
Output is correct |
16 |
Correct |
29 ms |
24440 KB |
Output is correct |
17 |
Correct |
328 ms |
24520 KB |
Output is correct |
18 |
Correct |
135 ms |
24696 KB |
Output is correct |
19 |
Correct |
30 ms |
24440 KB |
Output is correct |
20 |
Correct |
190 ms |
24568 KB |
Output is correct |
21 |
Correct |
48 ms |
26044 KB |
Output is correct |
22 |
Correct |
58 ms |
27000 KB |
Output is correct |
23 |
Correct |
69 ms |
27892 KB |
Output is correct |
24 |
Execution timed out |
4019 ms |
25568 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
23800 KB |
Output is correct |
2 |
Correct |
27 ms |
24056 KB |
Output is correct |
3 |
Correct |
28 ms |
24056 KB |
Output is correct |
4 |
Correct |
23 ms |
23800 KB |
Output is correct |
5 |
Correct |
24 ms |
23928 KB |
Output is correct |
6 |
Correct |
25 ms |
24056 KB |
Output is correct |
7 |
Correct |
28 ms |
23928 KB |
Output is correct |
8 |
Correct |
25 ms |
24056 KB |
Output is correct |
9 |
Correct |
30 ms |
24184 KB |
Output is correct |
10 |
Correct |
31 ms |
24184 KB |
Output is correct |
11 |
Correct |
451 ms |
46384 KB |
Output is correct |
12 |
Correct |
1151 ms |
59416 KB |
Output is correct |
13 |
Correct |
1142 ms |
63856 KB |
Output is correct |
14 |
Correct |
1201 ms |
67176 KB |
Output is correct |
15 |
Correct |
1193 ms |
67044 KB |
Output is correct |
16 |
Correct |
1156 ms |
65912 KB |
Output is correct |
17 |
Correct |
1128 ms |
63516 KB |
Output is correct |
18 |
Correct |
1623 ms |
65500 KB |
Output is correct |
19 |
Correct |
1479 ms |
81908 KB |
Output is correct |
20 |
Correct |
878 ms |
77816 KB |
Output is correct |
21 |
Correct |
127 ms |
24220 KB |
Output is correct |
22 |
Correct |
56 ms |
24500 KB |
Output is correct |
23 |
Correct |
174 ms |
24444 KB |
Output is correct |
24 |
Correct |
105 ms |
24312 KB |
Output is correct |
25 |
Correct |
129 ms |
24312 KB |
Output is correct |
26 |
Correct |
29 ms |
24440 KB |
Output is correct |
27 |
Correct |
328 ms |
24520 KB |
Output is correct |
28 |
Correct |
135 ms |
24696 KB |
Output is correct |
29 |
Correct |
30 ms |
24440 KB |
Output is correct |
30 |
Correct |
190 ms |
24568 KB |
Output is correct |
31 |
Correct |
48 ms |
26044 KB |
Output is correct |
32 |
Correct |
58 ms |
27000 KB |
Output is correct |
33 |
Correct |
69 ms |
27892 KB |
Output is correct |
34 |
Execution timed out |
4019 ms |
25568 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |