#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000000;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
vector<vector<int>>len;
vector<int>cri;//Tじの候補
vector<int>uni[4];
vector<int>ran[4];
int rop[4]={0};//その状態でのループ数
int geans;
int Taru=0;
void Init(int n){
len.res(n);
geans=n;
cri.pub(0x869120);cri.pub(-1);cri.pub(-1);cri.pub(-1);
for(int j=0;j<4;j++){
ran[j].res(n);uni[j].res(n);
for(int i=0;i<n;i++){ran[j][i]=1;uni[j][i]=i;}
}
}
int en=-1;
int sta;
vector<int>dfit;
vector<int>hai;
vector<pair<int,int>>queri;
bool unfi(int A,int B,int bas){
if(cri[bas]==A||cri[bas]==B){return false;}
int a=A,b=B;
while(a!=uni[bas][a]){a=uni[bas][a];}
while(b!=uni[bas][b]){b=uni[bas][b];}
if(ran[bas][a]<ran[bas][b]){swap(a,b);}
uni[bas][b]=a;
if(a==b){rop[bas]++;}
else{ran[bas][a]+=ran[bas][b];}
return (a==b);
}
void reki(int bas){
for(int i=0;i<len.size();i++){uni[bas][i]=i;ran[bas][i]=1;}
for(auto it:queri){unfi(it.fir,it.sec,bas);}
}
void Link(int A,int B){
len[A].pub(B);
len[B].pub(A);
if(Taru){
if(len[A].size()==3){
for(auto &it:cri){
if(it!=A&&it!=len[A][0]&&it!=len[A][1]&&it!=len[A][2]){it=-1;}
}
}
if(len[A].size()>3){
for(auto &it:cri){if(it!=A){it=-1;}}
}
}else if(len[A].size()==3){
Taru=1;
cri.clear();
rop[0]=0;
cri.pub(A);reki(0);
cri.pub(len[A][0]);reki(1);
cri.pub(len[A][1]);reki(2);
cri.pub(len[A][2]);reki(3);
}
if(Taru){
if(len[B].size()==3){
for(auto &it:cri){
if(it!=B&&it!=len[B][0]&&it!=len[B][1]&&it!=len[B][2]){it=-1;}
}
}
if(len[B].size()>3){
for(auto &it:cri){if(it!=B){it=-1;}}
}
}else if(len[B].size()==3){
Taru=1;
rop[0]=0;
cri.clear();
cri.pub(B);reki(0);//構築する
cri.pub(len[B][0]);reki(1);
cri.pub(len[B][1]);reki(2);
cri.pub(len[B][2]);reki(3);
}
queri.pub(mp(A,B));
if(Taru){geans=0;}
for(int j=0;j<4;j++){
if(cri[j]==-1){continue;}
bool ret=unfi(A,B,j);
if((!Taru)&&ret&&rop[j]==1){
int a=A;
while(a!=uni[j][a]){a=uni[j][a];}
geans=ran[j][a];
}
if((!Taru)&&rop[j]==2){geans=0;}
if(Taru&&rop[j]>0){cri[j]=-1;}
if(Taru&&rop[j]==0){geans++;}
}
}
int CountCritical(void){return geans;}
Compilation message
rings.cpp: In function 'void reki(int)':
rings.cpp:87:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<len.size();i++){uni[bas][i]=i;ran[bas][i]=1;}
~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
764 KB |
Output is correct |
3 |
Correct |
5 ms |
952 KB |
Output is correct |
4 |
Correct |
2 ms |
952 KB |
Output is correct |
5 |
Correct |
3 ms |
952 KB |
Output is correct |
6 |
Correct |
5 ms |
1048 KB |
Output is correct |
7 |
Correct |
2 ms |
1048 KB |
Output is correct |
8 |
Correct |
4 ms |
1048 KB |
Output is correct |
9 |
Correct |
5 ms |
1048 KB |
Output is correct |
10 |
Correct |
7 ms |
1076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
466 ms |
49468 KB |
Output is correct |
2 |
Correct |
1012 ms |
75812 KB |
Output is correct |
3 |
Correct |
969 ms |
90072 KB |
Output is correct |
4 |
Correct |
1257 ms |
94540 KB |
Output is correct |
5 |
Correct |
1272 ms |
94540 KB |
Output is correct |
6 |
Correct |
1196 ms |
94540 KB |
Output is correct |
7 |
Correct |
971 ms |
94540 KB |
Output is correct |
8 |
Correct |
1366 ms |
94540 KB |
Output is correct |
9 |
Correct |
1484 ms |
94596 KB |
Output is correct |
10 |
Correct |
846 ms |
94596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
764 KB |
Output is correct |
3 |
Correct |
5 ms |
952 KB |
Output is correct |
4 |
Correct |
2 ms |
952 KB |
Output is correct |
5 |
Correct |
3 ms |
952 KB |
Output is correct |
6 |
Correct |
5 ms |
1048 KB |
Output is correct |
7 |
Correct |
2 ms |
1048 KB |
Output is correct |
8 |
Correct |
4 ms |
1048 KB |
Output is correct |
9 |
Correct |
5 ms |
1048 KB |
Output is correct |
10 |
Correct |
7 ms |
1076 KB |
Output is correct |
11 |
Correct |
5 ms |
94596 KB |
Output is correct |
12 |
Correct |
8 ms |
94596 KB |
Output is correct |
13 |
Correct |
8 ms |
94596 KB |
Output is correct |
14 |
Correct |
6 ms |
94596 KB |
Output is correct |
15 |
Correct |
6 ms |
94596 KB |
Output is correct |
16 |
Correct |
7 ms |
94596 KB |
Output is correct |
17 |
Correct |
7 ms |
94596 KB |
Output is correct |
18 |
Correct |
9 ms |
94596 KB |
Output is correct |
19 |
Correct |
11 ms |
94596 KB |
Output is correct |
20 |
Correct |
13 ms |
94596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
764 KB |
Output is correct |
3 |
Correct |
5 ms |
952 KB |
Output is correct |
4 |
Correct |
2 ms |
952 KB |
Output is correct |
5 |
Correct |
3 ms |
952 KB |
Output is correct |
6 |
Correct |
5 ms |
1048 KB |
Output is correct |
7 |
Correct |
2 ms |
1048 KB |
Output is correct |
8 |
Correct |
4 ms |
1048 KB |
Output is correct |
9 |
Correct |
5 ms |
1048 KB |
Output is correct |
10 |
Correct |
7 ms |
1076 KB |
Output is correct |
11 |
Correct |
5 ms |
94596 KB |
Output is correct |
12 |
Correct |
8 ms |
94596 KB |
Output is correct |
13 |
Correct |
8 ms |
94596 KB |
Output is correct |
14 |
Correct |
6 ms |
94596 KB |
Output is correct |
15 |
Correct |
6 ms |
94596 KB |
Output is correct |
16 |
Correct |
7 ms |
94596 KB |
Output is correct |
17 |
Correct |
7 ms |
94596 KB |
Output is correct |
18 |
Correct |
9 ms |
94596 KB |
Output is correct |
19 |
Correct |
11 ms |
94596 KB |
Output is correct |
20 |
Correct |
13 ms |
94596 KB |
Output is correct |
21 |
Correct |
24 ms |
94596 KB |
Output is correct |
22 |
Correct |
39 ms |
94596 KB |
Output is correct |
23 |
Correct |
51 ms |
94596 KB |
Output is correct |
24 |
Correct |
51 ms |
94596 KB |
Output is correct |
25 |
Correct |
21 ms |
94596 KB |
Output is correct |
26 |
Correct |
64 ms |
94596 KB |
Output is correct |
27 |
Correct |
66 ms |
94596 KB |
Output is correct |
28 |
Correct |
58 ms |
94596 KB |
Output is correct |
29 |
Correct |
37 ms |
94596 KB |
Output is correct |
30 |
Correct |
70 ms |
94596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
764 KB |
Output is correct |
3 |
Correct |
5 ms |
952 KB |
Output is correct |
4 |
Correct |
2 ms |
952 KB |
Output is correct |
5 |
Correct |
3 ms |
952 KB |
Output is correct |
6 |
Correct |
5 ms |
1048 KB |
Output is correct |
7 |
Correct |
2 ms |
1048 KB |
Output is correct |
8 |
Correct |
4 ms |
1048 KB |
Output is correct |
9 |
Correct |
5 ms |
1048 KB |
Output is correct |
10 |
Correct |
7 ms |
1076 KB |
Output is correct |
11 |
Correct |
466 ms |
49468 KB |
Output is correct |
12 |
Correct |
1012 ms |
75812 KB |
Output is correct |
13 |
Correct |
969 ms |
90072 KB |
Output is correct |
14 |
Correct |
1257 ms |
94540 KB |
Output is correct |
15 |
Correct |
1272 ms |
94540 KB |
Output is correct |
16 |
Correct |
1196 ms |
94540 KB |
Output is correct |
17 |
Correct |
971 ms |
94540 KB |
Output is correct |
18 |
Correct |
1366 ms |
94540 KB |
Output is correct |
19 |
Correct |
1484 ms |
94596 KB |
Output is correct |
20 |
Correct |
846 ms |
94596 KB |
Output is correct |
21 |
Correct |
5 ms |
94596 KB |
Output is correct |
22 |
Correct |
8 ms |
94596 KB |
Output is correct |
23 |
Correct |
8 ms |
94596 KB |
Output is correct |
24 |
Correct |
6 ms |
94596 KB |
Output is correct |
25 |
Correct |
6 ms |
94596 KB |
Output is correct |
26 |
Correct |
7 ms |
94596 KB |
Output is correct |
27 |
Correct |
7 ms |
94596 KB |
Output is correct |
28 |
Correct |
9 ms |
94596 KB |
Output is correct |
29 |
Correct |
11 ms |
94596 KB |
Output is correct |
30 |
Correct |
13 ms |
94596 KB |
Output is correct |
31 |
Correct |
24 ms |
94596 KB |
Output is correct |
32 |
Correct |
39 ms |
94596 KB |
Output is correct |
33 |
Correct |
51 ms |
94596 KB |
Output is correct |
34 |
Correct |
51 ms |
94596 KB |
Output is correct |
35 |
Correct |
21 ms |
94596 KB |
Output is correct |
36 |
Correct |
64 ms |
94596 KB |
Output is correct |
37 |
Correct |
66 ms |
94596 KB |
Output is correct |
38 |
Correct |
58 ms |
94596 KB |
Output is correct |
39 |
Correct |
37 ms |
94596 KB |
Output is correct |
40 |
Correct |
70 ms |
94596 KB |
Output is correct |
41 |
Correct |
256 ms |
94596 KB |
Output is correct |
42 |
Correct |
638 ms |
94596 KB |
Output is correct |
43 |
Correct |
308 ms |
94596 KB |
Output is correct |
44 |
Correct |
695 ms |
94596 KB |
Output is correct |
45 |
Correct |
827 ms |
94596 KB |
Output is correct |
46 |
Correct |
792 ms |
94596 KB |
Output is correct |
47 |
Correct |
1070 ms |
94596 KB |
Output is correct |
48 |
Correct |
530 ms |
94596 KB |
Output is correct |
49 |
Correct |
800 ms |
94596 KB |
Output is correct |
50 |
Correct |
894 ms |
94596 KB |
Output is correct |
51 |
Correct |
333 ms |
94596 KB |
Output is correct |
52 |
Correct |
608 ms |
94596 KB |
Output is correct |
53 |
Correct |
502 ms |
94596 KB |
Output is correct |
54 |
Correct |
1240 ms |
94596 KB |
Output is correct |
55 |
Correct |
1105 ms |
94596 KB |
Output is correct |