#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int> > adj[20005],tadj[20005];
int ans[20005];
bool start=false;
int turn=0;
string s="101001";
void dfs(int x, int p, int c){
int child=0;
for(auto i:tadj[x]){
if(i.first==p) continue;
child++;
}
if(child>1){
start=false;
turn=0;
for(auto i:tadj[x]){
if(i.first==p) continue;
ans[i.second]=1-c;
dfs(i.first,x,1-c);
}
}
else if(child==1){
if(!start){
start=true;
turn=1;
if(c==-1||c==1) turn=0;
else turn=2;
}
for(auto i:tadj[x]){
if(i.first==p) continue;
ans[i.second]=s[turn]-'0';
turn++;
turn%=6;
dfs(i.first,x,ans[i.second]);
}
}
}
vector<int> Mark(int N, int M, int A, int B, std::vector<int> U, std::vector<int> V){
vector<int> ret(M);
for(int i=0; i<M; i++) ret[i]=-1;
for(int i=0; i<M; i++){
adj[U[i]].push_back({V[i],i});
adj[V[i]].push_back({U[i],i});
}
if(A>2){
queue<pair<int,pair<int,int> > > q;
q.push({0,{0,-1}});
int v[N];
memset(v,0,sizeof(v));
while(!q.empty()){
int a=q.front().first,b=q.front().second.first,c=q.front().second.second;
q.pop();
if(v[b]) continue;
v[b]=1;
for(auto i:adj[b]){
if(ret[i.second]==-1) ret[i.second]=a%3;
if(!v[i.first]) q.push({a+1,{i.first,0}});
}
}
return ret;
}
else{
for(int i=0; i<M; i++){
tadj[U[i]].push_back({V[i],i});
tadj[V[i]].push_back({U[i],i});
}
}
dfs(0,-1,1);
for(int i=0; i<M; i++) ret[i]=ans[i];
return ret;
}
#include <bits/stdc++.h>
using namespace std;
bool start=true,confuse=false;
int mode=0;
void Init(int A, int B){
start=true;
confuse=false;
if(A>2) mode=1;
}
int pre=-1;
string cur="";
int Move(vector<int> y){
if(mode){
if(y[0]&&y[1]) return 0;
else if(y[1]&&y[2]) return 1;
else if(y[0]&&y[2]) return 2;
else if(y[0]) return 0;
else if(y[1]) return 1;
else if(y[2]) return 2;
else{
assert(false);
return -1;
}
}
if(!start&&!confuse){
if(y[0]+y[1]==1){
if(y[0]) return pre=0;
else return pre=1;
}
else if(y[0]+y[1]==0){
return -1;
}
//assert(y[1-pre]==1);
return pre=1-pre;
}
if(start){
start=false;
if(y[0]+y[1]==2){
confuse=true;
if(y[0]==2){
cur+="00";
return pre=0;
}
else if(y[1]==2){
cur+="11";
return pre=1;
}
else{
cur+="01";
return pre=1;
}
}
else{
if(y[0]==1) return pre=0;
else if(y[1]==1) return pre=1;
else{
assert(false);
return -1;
}
}
}
if(confuse){
if(y[0]+y[1]>1){
if(y[0]==0||y[1]==0){
confuse=false;
return -1;
}
confuse=false;
return pre=1-pre;
}
else if(y[0]+y[1]==0){
confuse=false;
return -1;
}
else{
if(cur.length()==4){
if(y[0]) cur+="0";
else cur+="1";
if(cur=="10100"||cur=="01001"||cur=="10011"||cur=="00110"||cur=="01101"||cur=="11010"){
cur="";
confuse=false;
return -1;
}
else{
cur="";
confuse=false;
if(y[0]) return pre=0;
else return pre=1;
}
}
if(y[0]){
cur+="0";
return pre=0;
}
else{
cur+="1";
return pre=1;
}
}
}
return 0;
}
Compilation message
Anthony.cpp: In function 'std::vector<int> Mark(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:54:51: warning: unused variable 'c' [-Wunused-variable]
54 | int a=q.front().first,b=q.front().second.first,c=q.front().second.second;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
15748 KB |
Output is correct |
2 |
Correct |
2 ms |
1544 KB |
Output is correct |
3 |
Correct |
30 ms |
15308 KB |
Output is correct |
4 |
Correct |
46 ms |
16976 KB |
Output is correct |
5 |
Correct |
53 ms |
16964 KB |
Output is correct |
6 |
Correct |
39 ms |
15732 KB |
Output is correct |
7 |
Correct |
40 ms |
15724 KB |
Output is correct |
8 |
Correct |
39 ms |
16432 KB |
Output is correct |
9 |
Correct |
49 ms |
16272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
15748 KB |
Output is correct |
2 |
Correct |
2 ms |
1544 KB |
Output is correct |
3 |
Correct |
30 ms |
15308 KB |
Output is correct |
4 |
Correct |
46 ms |
16976 KB |
Output is correct |
5 |
Correct |
53 ms |
16964 KB |
Output is correct |
6 |
Correct |
39 ms |
15732 KB |
Output is correct |
7 |
Correct |
40 ms |
15724 KB |
Output is correct |
8 |
Correct |
39 ms |
16432 KB |
Output is correct |
9 |
Correct |
49 ms |
16272 KB |
Output is correct |
10 |
Correct |
37 ms |
13720 KB |
Output is correct |
11 |
Correct |
37 ms |
13880 KB |
Output is correct |
12 |
Correct |
36 ms |
13796 KB |
Output is correct |
13 |
Correct |
32 ms |
13712 KB |
Output is correct |
14 |
Correct |
35 ms |
14048 KB |
Output is correct |
15 |
Correct |
39 ms |
14396 KB |
Output is correct |
16 |
Correct |
47 ms |
16436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
13444 KB |
Output is correct |
2 |
Correct |
1 ms |
1536 KB |
Output is correct |
3 |
Correct |
31 ms |
13100 KB |
Output is correct |
4 |
Correct |
46 ms |
14728 KB |
Output is correct |
5 |
Correct |
47 ms |
14740 KB |
Output is correct |
6 |
Correct |
38 ms |
13428 KB |
Output is correct |
7 |
Correct |
35 ms |
13484 KB |
Output is correct |
8 |
Correct |
38 ms |
14104 KB |
Output is correct |
9 |
Correct |
47 ms |
14012 KB |
Output is correct |
10 |
Correct |
43 ms |
13876 KB |
Output is correct |
11 |
Correct |
41 ms |
13768 KB |
Output is correct |
12 |
Correct |
39 ms |
13732 KB |
Output is correct |
13 |
Correct |
38 ms |
13804 KB |
Output is correct |
14 |
Correct |
43 ms |
14120 KB |
Output is correct |
15 |
Correct |
40 ms |
14188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
13444 KB |
Output is correct |
2 |
Correct |
1 ms |
1536 KB |
Output is correct |
3 |
Correct |
31 ms |
13100 KB |
Output is correct |
4 |
Correct |
46 ms |
14728 KB |
Output is correct |
5 |
Correct |
47 ms |
14740 KB |
Output is correct |
6 |
Correct |
38 ms |
13428 KB |
Output is correct |
7 |
Correct |
35 ms |
13484 KB |
Output is correct |
8 |
Correct |
38 ms |
14104 KB |
Output is correct |
9 |
Correct |
47 ms |
14012 KB |
Output is correct |
10 |
Correct |
43 ms |
13876 KB |
Output is correct |
11 |
Correct |
41 ms |
13768 KB |
Output is correct |
12 |
Correct |
39 ms |
13732 KB |
Output is correct |
13 |
Correct |
38 ms |
13804 KB |
Output is correct |
14 |
Correct |
43 ms |
14120 KB |
Output is correct |
15 |
Correct |
40 ms |
14188 KB |
Output is correct |
16 |
Correct |
30 ms |
11884 KB |
Output is correct |
17 |
Correct |
33 ms |
11984 KB |
Output is correct |
18 |
Correct |
36 ms |
11964 KB |
Output is correct |
19 |
Correct |
34 ms |
11876 KB |
Output is correct |
20 |
Correct |
38 ms |
12556 KB |
Output is correct |
21 |
Correct |
40 ms |
12224 KB |
Output is correct |
22 |
Correct |
44 ms |
14372 KB |
Output is correct |
23 |
Correct |
33 ms |
12012 KB |
Output is correct |
24 |
Correct |
35 ms |
11984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1796 KB |
Output is correct |
2 |
Correct |
2 ms |
1544 KB |
Output is correct |
3 |
Correct |
2 ms |
1804 KB |
Output is correct |
4 |
Correct |
2 ms |
1796 KB |
Output is correct |
5 |
Correct |
3 ms |
1804 KB |
Output is correct |
6 |
Correct |
3 ms |
1796 KB |
Output is correct |
7 |
Correct |
2 ms |
1808 KB |
Output is correct |
8 |
Correct |
3 ms |
1796 KB |
Output is correct |
9 |
Correct |
2 ms |
1796 KB |
Output is correct |
10 |
Correct |
2 ms |
1804 KB |
Output is correct |
11 |
Correct |
2 ms |
1804 KB |
Output is correct |
12 |
Correct |
2 ms |
1800 KB |
Output is correct |
13 |
Correct |
2 ms |
1804 KB |
Output is correct |
14 |
Correct |
2 ms |
1796 KB |
Output is correct |
15 |
Correct |
2 ms |
1804 KB |
Output is correct |
16 |
Correct |
2 ms |
1796 KB |
Output is correct |
17 |
Correct |
3 ms |
1804 KB |
Output is correct |
18 |
Correct |
2 ms |
1804 KB |
Output is correct |
19 |
Correct |
2 ms |
1804 KB |
Output is correct |
20 |
Correct |
3 ms |
1796 KB |
Output is correct |
21 |
Correct |
3 ms |
1796 KB |
Output is correct |
22 |
Correct |
3 ms |
1804 KB |
Output is correct |
23 |
Correct |
2 ms |
1796 KB |
Output is correct |
24 |
Correct |
2 ms |
1796 KB |
Output is correct |
25 |
Correct |
2 ms |
1796 KB |
Output is correct |
26 |
Correct |
2 ms |
1804 KB |
Output is correct |
27 |
Correct |
2 ms |
1796 KB |
Output is correct |
28 |
Correct |
2 ms |
1796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
12388 KB |
Output is correct |
2 |
Correct |
43 ms |
13260 KB |
Output is correct |
3 |
Correct |
2 ms |
1536 KB |
Output is correct |
4 |
Correct |
35 ms |
12272 KB |
Output is correct |
5 |
Correct |
63 ms |
14708 KB |
Output is correct |
6 |
Correct |
46 ms |
14704 KB |
Output is correct |
7 |
Correct |
38 ms |
13744 KB |
Output is correct |
8 |
Correct |
43 ms |
13696 KB |
Output is correct |
9 |
Correct |
55 ms |
14688 KB |
Output is correct |
10 |
Correct |
56 ms |
14476 KB |
Output is correct |
11 |
Correct |
42 ms |
14556 KB |
Output is correct |
12 |
Correct |
49 ms |
14460 KB |
Output is correct |
13 |
Correct |
50 ms |
14588 KB |
Output is correct |
14 |
Correct |
41 ms |
14560 KB |
Output is correct |
15 |
Correct |
46 ms |
14628 KB |
Output is correct |
16 |
Correct |
44 ms |
14560 KB |
Output is correct |
17 |
Correct |
39 ms |
14352 KB |
Output is correct |
18 |
Correct |
43 ms |
14356 KB |
Output is correct |
19 |
Correct |
39 ms |
14376 KB |
Output is correct |
20 |
Correct |
39 ms |
14372 KB |
Output is correct |
21 |
Correct |
41 ms |
14416 KB |
Output is correct |
22 |
Correct |
39 ms |
14436 KB |
Output is correct |
23 |
Correct |
37 ms |
12412 KB |
Output is correct |
24 |
Correct |
37 ms |
12304 KB |
Output is correct |
25 |
Correct |
36 ms |
12668 KB |
Output is correct |
26 |
Correct |
34 ms |
12832 KB |
Output is correct |
27 |
Correct |
42 ms |
13452 KB |
Output is correct |
28 |
Correct |
49 ms |
13472 KB |
Output is correct |
29 |
Correct |
46 ms |
13496 KB |
Output is correct |
30 |
Correct |
51 ms |
13504 KB |
Output is correct |
31 |
Correct |
36 ms |
12384 KB |
Output is correct |
32 |
Correct |
31 ms |
12456 KB |
Output is correct |
33 |
Correct |
34 ms |
12784 KB |
Output is correct |
34 |
Correct |
34 ms |
12756 KB |
Output is correct |
35 |
Correct |
39 ms |
13360 KB |
Output is correct |
36 |
Correct |
40 ms |
13392 KB |
Output is correct |
37 |
Correct |
41 ms |
13504 KB |
Output is correct |
38 |
Correct |
40 ms |
13496 KB |
Output is correct |
39 |
Correct |
38 ms |
13340 KB |
Output is correct |
40 |
Correct |
41 ms |
13400 KB |
Output is correct |
41 |
Correct |
49 ms |
13988 KB |
Output is correct |
42 |
Correct |
41 ms |
13788 KB |
Output is correct |
43 |
Correct |
46 ms |
13928 KB |
Output is correct |
44 |
Correct |
43 ms |
13948 KB |
Output is correct |
45 |
Correct |
40 ms |
14068 KB |
Output is correct |
46 |
Correct |
49 ms |
13948 KB |
Output is correct |
47 |
Correct |
45 ms |
13088 KB |
Output is correct |
48 |
Correct |
42 ms |
13340 KB |
Output is correct |
49 |
Correct |
38 ms |
13116 KB |
Output is correct |
50 |
Correct |
43 ms |
13160 KB |
Output is correct |
51 |
Correct |
41 ms |
12320 KB |
Output is correct |
52 |
Correct |
37 ms |
12324 KB |
Output is correct |
53 |
Correct |
38 ms |
12248 KB |
Output is correct |
54 |
Correct |
36 ms |
12336 KB |
Output is correct |
55 |
Correct |
40 ms |
12212 KB |
Output is correct |
56 |
Correct |
38 ms |
12348 KB |
Output is correct |
57 |
Correct |
49 ms |
12340 KB |
Output is correct |
58 |
Correct |
38 ms |
12380 KB |
Output is correct |
59 |
Correct |
36 ms |
12480 KB |
Output is correct |
60 |
Correct |
45 ms |
12332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
12388 KB |
Output is correct |
2 |
Correct |
36 ms |
13336 KB |
Output is correct |
3 |
Correct |
1 ms |
1544 KB |
Output is correct |
4 |
Correct |
28 ms |
12216 KB |
Output is correct |
5 |
Correct |
43 ms |
14544 KB |
Output is correct |
6 |
Correct |
44 ms |
14612 KB |
Output is correct |
7 |
Correct |
36 ms |
13764 KB |
Output is correct |
8 |
Correct |
38 ms |
13868 KB |
Output is correct |
9 |
Correct |
49 ms |
14628 KB |
Output is correct |
10 |
Correct |
44 ms |
14608 KB |
Output is correct |
11 |
Correct |
45 ms |
14612 KB |
Output is correct |
12 |
Correct |
43 ms |
14692 KB |
Output is correct |
13 |
Correct |
44 ms |
14612 KB |
Output is correct |
14 |
Correct |
46 ms |
14560 KB |
Output is correct |
15 |
Correct |
42 ms |
14616 KB |
Output is correct |
16 |
Correct |
44 ms |
14552 KB |
Output is correct |
17 |
Correct |
41 ms |
14372 KB |
Output is correct |
18 |
Correct |
40 ms |
14252 KB |
Output is correct |
19 |
Correct |
42 ms |
14448 KB |
Output is correct |
20 |
Correct |
39 ms |
14268 KB |
Output is correct |
21 |
Correct |
39 ms |
14444 KB |
Output is correct |
22 |
Correct |
40 ms |
14280 KB |
Output is correct |
23 |
Correct |
33 ms |
12400 KB |
Output is correct |
24 |
Correct |
36 ms |
12256 KB |
Output is correct |
25 |
Correct |
33 ms |
12652 KB |
Output is correct |
26 |
Correct |
34 ms |
12624 KB |
Output is correct |
27 |
Correct |
39 ms |
13512 KB |
Output is correct |
28 |
Correct |
38 ms |
13520 KB |
Output is correct |
29 |
Correct |
40 ms |
13572 KB |
Output is correct |
30 |
Correct |
41 ms |
13472 KB |
Output is correct |
31 |
Correct |
33 ms |
12300 KB |
Output is correct |
32 |
Correct |
36 ms |
12348 KB |
Output is correct |
33 |
Correct |
33 ms |
12788 KB |
Output is correct |
34 |
Correct |
37 ms |
12816 KB |
Output is correct |
35 |
Correct |
38 ms |
13420 KB |
Output is correct |
36 |
Correct |
38 ms |
13440 KB |
Output is correct |
37 |
Correct |
41 ms |
13444 KB |
Output is correct |
38 |
Correct |
38 ms |
13428 KB |
Output is correct |
39 |
Correct |
39 ms |
13360 KB |
Output is correct |
40 |
Correct |
38 ms |
13424 KB |
Output is correct |
41 |
Correct |
41 ms |
13920 KB |
Output is correct |
42 |
Correct |
39 ms |
13896 KB |
Output is correct |
43 |
Correct |
41 ms |
14000 KB |
Output is correct |
44 |
Correct |
39 ms |
14000 KB |
Output is correct |
45 |
Correct |
45 ms |
14084 KB |
Output is correct |
46 |
Correct |
45 ms |
13876 KB |
Output is correct |
47 |
Correct |
41 ms |
13140 KB |
Output is correct |
48 |
Correct |
37 ms |
13300 KB |
Output is correct |
49 |
Correct |
37 ms |
13260 KB |
Output is correct |
50 |
Correct |
38 ms |
13332 KB |
Output is correct |
51 |
Correct |
36 ms |
12248 KB |
Output is correct |
52 |
Correct |
34 ms |
12396 KB |
Output is correct |
53 |
Correct |
36 ms |
12360 KB |
Output is correct |
54 |
Correct |
35 ms |
12396 KB |
Output is correct |
55 |
Correct |
38 ms |
12316 KB |
Output is correct |
56 |
Correct |
37 ms |
12736 KB |
Output is correct |
57 |
Correct |
35 ms |
12804 KB |
Output is correct |
58 |
Correct |
38 ms |
12824 KB |
Output is correct |
59 |
Correct |
36 ms |
12952 KB |
Output is correct |
60 |
Correct |
36 ms |
12812 KB |
Output is correct |