#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int> > e;
struct graph
{
int v,par[1000005],deg[1000005],sz[1000005],cyc,csz;
pair<int,int> mx;
graph()
{
v=-1;
cyc=0;
mx={0,0};
for (int i=0;i<1e6;i++)
{
par[i]=i;
deg[i]=0;
sz[i]=1;
}
}
int find(int x)
{
if (par[x]!=x)
par[x]=find(par[x]);
return par[x];
}
void Union(int x,int y)
{
deg[x]++;
deg[y]++;
mx=max(mx,{deg[x],x});
mx=max(mx,{deg[y],y});
x=find(x);
y=find(y);
if (x==y)
{
cyc++;
csz=sz[x];
}
else
{
par[x]=y;
sz[y]+=sz[x];
}
}
};
int n;
graph g[5];
bool f;
void Init(int nn)
{
n=nn;
}
void Link(int a,int b)
{
e.push_back({a,b});
if (!f)
{
g[0].Union(a,b);
if (g[0].mx.first==3)
{
f=1;
vector<int> cur({g[0].mx.second});
for (auto p:e)
{
if (p.first==cur[0] || p.second==cur[0])
cur.push_back(p.first^p.second^cur[0]);
}
for (int i=0;i<4;i++)
{
g[i+1].v=cur[i];
for (auto p:e)
{
if (p.first!=cur[i] && p.second!=cur[i])
g[i+1].Union(p.first,p.second);
}
}
}
}
else
{
for (int i=1;i<5;i++)
{
if (g[i].v!=a && g[i].v!=b)
g[i].Union(a,b);
}
}
}
int CountCritical()
{
if (!f)
{
if (!g[0].cyc)
return n;
if (g[0].cyc>1)
return 0;
return g[0].csz;
}
int ans=0;
for (int i=1;i<5;i++)
ans+=(g[i].mx.first<=2 && !g[i].cyc);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
59000 KB |
Output is correct |
2 |
Correct |
58 ms |
59132 KB |
Output is correct |
3 |
Correct |
58 ms |
59340 KB |
Output is correct |
4 |
Correct |
57 ms |
59128 KB |
Output is correct |
5 |
Correct |
57 ms |
59128 KB |
Output is correct |
6 |
Correct |
57 ms |
59256 KB |
Output is correct |
7 |
Correct |
65 ms |
59000 KB |
Output is correct |
8 |
Correct |
57 ms |
59128 KB |
Output is correct |
9 |
Correct |
57 ms |
59256 KB |
Output is correct |
10 |
Correct |
58 ms |
59256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
288 ms |
63720 KB |
Output is correct |
2 |
Correct |
1575 ms |
68092 KB |
Output is correct |
3 |
Correct |
2690 ms |
79336 KB |
Output is correct |
4 |
Correct |
720 ms |
80592 KB |
Output is correct |
5 |
Correct |
641 ms |
80560 KB |
Output is correct |
6 |
Correct |
721 ms |
79724 KB |
Output is correct |
7 |
Correct |
2484 ms |
78676 KB |
Output is correct |
8 |
Correct |
1507 ms |
79148 KB |
Output is correct |
9 |
Correct |
1465 ms |
80444 KB |
Output is correct |
10 |
Correct |
548 ms |
79872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
59000 KB |
Output is correct |
2 |
Correct |
58 ms |
59132 KB |
Output is correct |
3 |
Correct |
58 ms |
59340 KB |
Output is correct |
4 |
Correct |
57 ms |
59128 KB |
Output is correct |
5 |
Correct |
57 ms |
59128 KB |
Output is correct |
6 |
Correct |
57 ms |
59256 KB |
Output is correct |
7 |
Correct |
65 ms |
59000 KB |
Output is correct |
8 |
Correct |
57 ms |
59128 KB |
Output is correct |
9 |
Correct |
57 ms |
59256 KB |
Output is correct |
10 |
Correct |
58 ms |
59256 KB |
Output is correct |
11 |
Correct |
58 ms |
59252 KB |
Output is correct |
12 |
Correct |
62 ms |
59356 KB |
Output is correct |
13 |
Correct |
59 ms |
59392 KB |
Output is correct |
14 |
Correct |
59 ms |
59256 KB |
Output is correct |
15 |
Correct |
58 ms |
59256 KB |
Output is correct |
16 |
Correct |
58 ms |
59332 KB |
Output is correct |
17 |
Correct |
60 ms |
59324 KB |
Output is correct |
18 |
Correct |
63 ms |
59416 KB |
Output is correct |
19 |
Correct |
59 ms |
59356 KB |
Output is correct |
20 |
Correct |
61 ms |
59460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
59000 KB |
Output is correct |
2 |
Correct |
58 ms |
59132 KB |
Output is correct |
3 |
Correct |
58 ms |
59340 KB |
Output is correct |
4 |
Correct |
57 ms |
59128 KB |
Output is correct |
5 |
Correct |
57 ms |
59128 KB |
Output is correct |
6 |
Correct |
57 ms |
59256 KB |
Output is correct |
7 |
Correct |
65 ms |
59000 KB |
Output is correct |
8 |
Correct |
57 ms |
59128 KB |
Output is correct |
9 |
Correct |
57 ms |
59256 KB |
Output is correct |
10 |
Correct |
58 ms |
59256 KB |
Output is correct |
11 |
Correct |
58 ms |
59252 KB |
Output is correct |
12 |
Correct |
62 ms |
59356 KB |
Output is correct |
13 |
Correct |
59 ms |
59392 KB |
Output is correct |
14 |
Correct |
59 ms |
59256 KB |
Output is correct |
15 |
Correct |
58 ms |
59256 KB |
Output is correct |
16 |
Correct |
58 ms |
59332 KB |
Output is correct |
17 |
Correct |
60 ms |
59324 KB |
Output is correct |
18 |
Correct |
63 ms |
59416 KB |
Output is correct |
19 |
Correct |
59 ms |
59356 KB |
Output is correct |
20 |
Correct |
61 ms |
59460 KB |
Output is correct |
21 |
Correct |
71 ms |
59968 KB |
Output is correct |
22 |
Correct |
81 ms |
60536 KB |
Output is correct |
23 |
Correct |
94 ms |
60692 KB |
Output is correct |
24 |
Correct |
113 ms |
60516 KB |
Output is correct |
25 |
Correct |
69 ms |
59488 KB |
Output is correct |
26 |
Correct |
95 ms |
60660 KB |
Output is correct |
27 |
Correct |
89 ms |
61324 KB |
Output is correct |
28 |
Correct |
107 ms |
61100 KB |
Output is correct |
29 |
Correct |
91 ms |
60168 KB |
Output is correct |
30 |
Correct |
93 ms |
61200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
59000 KB |
Output is correct |
2 |
Correct |
58 ms |
59132 KB |
Output is correct |
3 |
Correct |
58 ms |
59340 KB |
Output is correct |
4 |
Correct |
57 ms |
59128 KB |
Output is correct |
5 |
Correct |
57 ms |
59128 KB |
Output is correct |
6 |
Correct |
57 ms |
59256 KB |
Output is correct |
7 |
Correct |
65 ms |
59000 KB |
Output is correct |
8 |
Correct |
57 ms |
59128 KB |
Output is correct |
9 |
Correct |
57 ms |
59256 KB |
Output is correct |
10 |
Correct |
58 ms |
59256 KB |
Output is correct |
11 |
Correct |
288 ms |
63720 KB |
Output is correct |
12 |
Correct |
1575 ms |
68092 KB |
Output is correct |
13 |
Correct |
2690 ms |
79336 KB |
Output is correct |
14 |
Correct |
720 ms |
80592 KB |
Output is correct |
15 |
Correct |
641 ms |
80560 KB |
Output is correct |
16 |
Correct |
721 ms |
79724 KB |
Output is correct |
17 |
Correct |
2484 ms |
78676 KB |
Output is correct |
18 |
Correct |
1507 ms |
79148 KB |
Output is correct |
19 |
Correct |
1465 ms |
80444 KB |
Output is correct |
20 |
Correct |
548 ms |
79872 KB |
Output is correct |
21 |
Correct |
58 ms |
59252 KB |
Output is correct |
22 |
Correct |
62 ms |
59356 KB |
Output is correct |
23 |
Correct |
59 ms |
59392 KB |
Output is correct |
24 |
Correct |
59 ms |
59256 KB |
Output is correct |
25 |
Correct |
58 ms |
59256 KB |
Output is correct |
26 |
Correct |
58 ms |
59332 KB |
Output is correct |
27 |
Correct |
60 ms |
59324 KB |
Output is correct |
28 |
Correct |
63 ms |
59416 KB |
Output is correct |
29 |
Correct |
59 ms |
59356 KB |
Output is correct |
30 |
Correct |
61 ms |
59460 KB |
Output is correct |
31 |
Correct |
71 ms |
59968 KB |
Output is correct |
32 |
Correct |
81 ms |
60536 KB |
Output is correct |
33 |
Correct |
94 ms |
60692 KB |
Output is correct |
34 |
Correct |
113 ms |
60516 KB |
Output is correct |
35 |
Correct |
69 ms |
59488 KB |
Output is correct |
36 |
Correct |
95 ms |
60660 KB |
Output is correct |
37 |
Correct |
89 ms |
61324 KB |
Output is correct |
38 |
Correct |
107 ms |
61100 KB |
Output is correct |
39 |
Correct |
91 ms |
60168 KB |
Output is correct |
40 |
Correct |
93 ms |
61200 KB |
Output is correct |
41 |
Correct |
218 ms |
66668 KB |
Output is correct |
42 |
Correct |
650 ms |
71840 KB |
Output is correct |
43 |
Correct |
382 ms |
64868 KB |
Output is correct |
44 |
Correct |
1426 ms |
78664 KB |
Output is correct |
45 |
Correct |
1603 ms |
76268 KB |
Output is correct |
46 |
Correct |
546 ms |
78516 KB |
Output is correct |
47 |
Correct |
540 ms |
78680 KB |
Output is correct |
48 |
Correct |
1026 ms |
69952 KB |
Output is correct |
49 |
Correct |
501 ms |
77524 KB |
Output is correct |
50 |
Correct |
521 ms |
77232 KB |
Output is correct |
51 |
Correct |
497 ms |
65464 KB |
Output is correct |
52 |
Correct |
1229 ms |
75880 KB |
Output is correct |
53 |
Correct |
1153 ms |
69264 KB |
Output is correct |
54 |
Correct |
1527 ms |
77844 KB |
Output is correct |
55 |
Correct |
2286 ms |
78616 KB |
Output is correct |