#include "Anthony.h"
#include<bits/stdc++.h>
using namespace std;
namespace {
const int seq[]={1,0,1,1,0,0};
int n,tot;
int v[40005],nxt[40005],h[20005],d[20005],q[20005],idx[20005];
vector<int> ret;
void addedge(int x,int y){
v[++tot]=y; nxt[tot]=h[x]; h[x]=tot;
v[++tot]=x; nxt[tot]=h[y]; h[y]=tot;
}
void bfs(){
for(int i=0;i<n;i++) d[i]=-1;
int front=0,rear=0;
q[rear++]=0; d[0]=0;
while(front<rear){
int x=q[front];
for(int p=h[x];p;p=nxt[p]){
if(d[v[p]]==-1){
d[v[p]]=d[x]+1;
q[rear++]=v[p];
}
}
++front;
}
}
void dfs(int x,int fa,int lst,int i){
int ch=0;
for(int p=h[x];p;p=nxt[p]) if(v[p]!=fa) ch++;
if(ch==0) return;
if(ch==1){
for(int p=h[x];p;p=nxt[p]){
if(v[p]==fa) continue;
ret[idx[v[p]]]=(lst^seq[i]);
dfs(v[p],x,lst,(i+1)%6);
}
}else{
for(int p=h[x];p;p=nxt[p]){
if(v[p]==fa) continue;
ret[idx[v[p]]]=(x==0?0:ret[idx[x]])^1;
dfs(v[p],x,x==0?0:ret[idx[x]],1);
}
}
}
}
vector<int> Mark(int n,int m,int a,int b,vector<int> u,vector<int> v){
::n=n;
tot=0;
for(int i=0;i<n;i++) h[i]=0;
for(int i=0;i<m;i++) addedge(u[i],v[i]);
if(a>=3){
bfs();
vector<int> col(m);
for(int i=0;i<m;i++) col[i]=min(d[u[i]],d[v[i]])%3;
return col;
}else{
bfs();
for(int i=0;i<m;i++){
if(d[u[i]]>d[v[i]]) swap(u[i],v[i]);
idx[v[i]]=i;
}
ret.resize(m);
dfs(0,0,0,0);
return ret;
}
return vector<int>(m,0);
}
#include "Catherine.h"
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
namespace {
const int seq[]={1,0,1,1,0,0};
int a,b;
bool up;
vector<int> edg,pth;
bool Down(){
for(int i=0;i<6;i++){
int cnt=0;
for(int j=0;j<(int)pth.size();j++){
cnt+=(seq[(i+j)%6]==pth[j]);
}
if(cnt==0||cnt==(int)pth.size()) return true;
}
return false;
}
} // namespace
void Init(int A,int B){
a=A; b=B;
up=false;
edg.clear();
pth.clear();
}
int Move(vector<int> y){
if(a>=3){
int cnt=0;
for(int i=0;i<a;i++) cnt+=(y[i]>0?1:0);
if(cnt==1){
for(int i=0;i<a;i++) if(y[i]>0) return i;
}
for(int i=0;i<a;i++){
if(y[i]>0&&y[(i+1)%3]>0) return i;
}
}
if(up){
if(y[0]==0&&y[1]==0){
edg.pb(edg.back());
return -1;
}
if(y[0]==0){
assert(y[1]>0);
edg.pb(1);
return 1;
}
if(y[1]==0){
assert(y[0]>0);
edg.pb(0);
return 0;
}
int t=edg.back();
edg.pb(t^1);
return t^1;
}
if(y[0]+y[1]+(!edg.empty()?1:0)==1){
up=true;
if(!edg.empty()) y[edg.back()]++;
for(int i=0;i<2;i++){
if(y[i]==1){
int v;
if(!edg.empty()&&edg.back()==i) v=-1;
else v=i;
edg.pb(i);
return v;
}
}
}
if(y[0]+y[1]+(!edg.empty()?1:0)>2){
up=true;
if(!edg.empty()) y[edg.back()]++;
for(int i=0;i<2;i++){
if(y[i]==1){
int v;
if(!edg.empty()&&edg.back()==i) v=-1;
else v=i;
edg.pb(i);
return v;
}
}
}
if((int)edg.size()<3){
if(y[0]==0&&y[1]==0){
up=true;
edg.pb(edg.back());
return -1;
}
if(y[0]==0){
edg.pb(1);
pth.pb(1);
if(y[1]==2) pth.pb(1);
return 1;
}
if(y[1]!=0) pth.pb(1);
else if(y[0]==2) pth.pb(0);
edg.pb(0);
pth.pb(0);
return 0;
}
if(y[0]==1) pth.pb(0);
else assert(y[1]>0),pth.pb(1);
if(!Down()){
up=true;
edg.pb(edg.back());
return -1;
}else{
up=true;
if(y[0]==1){
edg.pb(0);
return 0;
}else{
assert(y[1]>0);
edg.pb(1);
return 1;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
14800 KB |
Output is correct |
2 |
Correct |
0 ms |
788 KB |
Output is correct |
3 |
Correct |
23 ms |
14016 KB |
Output is correct |
4 |
Correct |
35 ms |
16068 KB |
Output is correct |
5 |
Correct |
35 ms |
15920 KB |
Output is correct |
6 |
Correct |
31 ms |
14784 KB |
Output is correct |
7 |
Correct |
27 ms |
14804 KB |
Output is correct |
8 |
Correct |
39 ms |
15496 KB |
Output is correct |
9 |
Correct |
33 ms |
15260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
14800 KB |
Output is correct |
2 |
Correct |
0 ms |
788 KB |
Output is correct |
3 |
Correct |
23 ms |
14016 KB |
Output is correct |
4 |
Correct |
35 ms |
16068 KB |
Output is correct |
5 |
Correct |
35 ms |
15920 KB |
Output is correct |
6 |
Correct |
31 ms |
14784 KB |
Output is correct |
7 |
Correct |
27 ms |
14804 KB |
Output is correct |
8 |
Correct |
39 ms |
15496 KB |
Output is correct |
9 |
Correct |
33 ms |
15260 KB |
Output is correct |
10 |
Correct |
24 ms |
12908 KB |
Output is correct |
11 |
Correct |
24 ms |
12920 KB |
Output is correct |
12 |
Correct |
26 ms |
12888 KB |
Output is correct |
13 |
Correct |
24 ms |
12824 KB |
Output is correct |
14 |
Correct |
26 ms |
12996 KB |
Output is correct |
15 |
Correct |
27 ms |
13396 KB |
Output is correct |
16 |
Correct |
43 ms |
15472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
12400 KB |
Output is correct |
2 |
Correct |
1 ms |
796 KB |
Output is correct |
3 |
Correct |
22 ms |
12036 KB |
Output is correct |
4 |
Correct |
32 ms |
13936 KB |
Output is correct |
5 |
Correct |
31 ms |
13916 KB |
Output is correct |
6 |
Correct |
24 ms |
12416 KB |
Output is correct |
7 |
Correct |
24 ms |
12412 KB |
Output is correct |
8 |
Correct |
28 ms |
13172 KB |
Output is correct |
9 |
Correct |
28 ms |
13172 KB |
Output is correct |
10 |
Correct |
33 ms |
12760 KB |
Output is correct |
11 |
Correct |
26 ms |
12920 KB |
Output is correct |
12 |
Correct |
28 ms |
12864 KB |
Output is correct |
13 |
Correct |
28 ms |
12916 KB |
Output is correct |
14 |
Correct |
28 ms |
13092 KB |
Output is correct |
15 |
Correct |
28 ms |
13144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
12400 KB |
Output is correct |
2 |
Correct |
1 ms |
796 KB |
Output is correct |
3 |
Correct |
22 ms |
12036 KB |
Output is correct |
4 |
Correct |
32 ms |
13936 KB |
Output is correct |
5 |
Correct |
31 ms |
13916 KB |
Output is correct |
6 |
Correct |
24 ms |
12416 KB |
Output is correct |
7 |
Correct |
24 ms |
12412 KB |
Output is correct |
8 |
Correct |
28 ms |
13172 KB |
Output is correct |
9 |
Correct |
28 ms |
13172 KB |
Output is correct |
10 |
Correct |
33 ms |
12760 KB |
Output is correct |
11 |
Correct |
26 ms |
12920 KB |
Output is correct |
12 |
Correct |
28 ms |
12864 KB |
Output is correct |
13 |
Correct |
28 ms |
12916 KB |
Output is correct |
14 |
Correct |
28 ms |
13092 KB |
Output is correct |
15 |
Correct |
28 ms |
13144 KB |
Output is correct |
16 |
Correct |
22 ms |
10860 KB |
Output is correct |
17 |
Correct |
22 ms |
10868 KB |
Output is correct |
18 |
Correct |
23 ms |
11032 KB |
Output is correct |
19 |
Correct |
23 ms |
10868 KB |
Output is correct |
20 |
Correct |
26 ms |
11636 KB |
Output is correct |
21 |
Correct |
26 ms |
11368 KB |
Output is correct |
22 |
Correct |
28 ms |
13420 KB |
Output is correct |
23 |
Correct |
23 ms |
11124 KB |
Output is correct |
24 |
Correct |
24 ms |
11128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1056 KB |
Output is correct |
2 |
Correct |
1 ms |
952 KB |
Output is correct |
3 |
Correct |
0 ms |
1060 KB |
Output is correct |
4 |
Correct |
1 ms |
1044 KB |
Output is correct |
5 |
Correct |
1 ms |
1052 KB |
Output is correct |
6 |
Correct |
2 ms |
1052 KB |
Output is correct |
7 |
Correct |
2 ms |
1056 KB |
Output is correct |
8 |
Correct |
1 ms |
1052 KB |
Output is correct |
9 |
Correct |
1 ms |
1056 KB |
Output is correct |
10 |
Correct |
1 ms |
1060 KB |
Output is correct |
11 |
Correct |
1 ms |
1052 KB |
Output is correct |
12 |
Correct |
1 ms |
1048 KB |
Output is correct |
13 |
Correct |
2 ms |
1056 KB |
Output is correct |
14 |
Correct |
1 ms |
1056 KB |
Output is correct |
15 |
Correct |
2 ms |
1048 KB |
Output is correct |
16 |
Correct |
2 ms |
1212 KB |
Output is correct |
17 |
Correct |
2 ms |
1052 KB |
Output is correct |
18 |
Correct |
2 ms |
1048 KB |
Output is correct |
19 |
Correct |
1 ms |
1052 KB |
Output is correct |
20 |
Correct |
2 ms |
1048 KB |
Output is correct |
21 |
Correct |
1 ms |
1056 KB |
Output is correct |
22 |
Correct |
2 ms |
1048 KB |
Output is correct |
23 |
Correct |
0 ms |
1044 KB |
Output is correct |
24 |
Correct |
1 ms |
1040 KB |
Output is correct |
25 |
Correct |
1 ms |
1056 KB |
Output is correct |
26 |
Correct |
1 ms |
1052 KB |
Output is correct |
27 |
Correct |
0 ms |
1048 KB |
Output is correct |
28 |
Correct |
1 ms |
872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
10856 KB |
Output is correct |
2 |
Correct |
25 ms |
12140 KB |
Output is correct |
3 |
Correct |
1 ms |
952 KB |
Output is correct |
4 |
Correct |
21 ms |
10348 KB |
Output is correct |
5 |
Correct |
29 ms |
13692 KB |
Output is correct |
6 |
Correct |
29 ms |
13680 KB |
Output is correct |
7 |
Incorrect |
23 ms |
12868 KB |
Wrong Answer [6] |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
11120 KB |
Output is correct |
2 |
Correct |
25 ms |
12156 KB |
Output is correct |
3 |
Correct |
0 ms |
796 KB |
Output is correct |
4 |
Correct |
20 ms |
10364 KB |
Output is correct |
5 |
Correct |
29 ms |
13692 KB |
Output is correct |
6 |
Correct |
31 ms |
13684 KB |
Output is correct |
7 |
Correct |
26 ms |
12664 KB |
Output is correct |
8 |
Correct |
24 ms |
12660 KB |
Output is correct |
9 |
Correct |
30 ms |
13684 KB |
Output is correct |
10 |
Correct |
30 ms |
13860 KB |
Output is correct |
11 |
Correct |
29 ms |
13728 KB |
Output is correct |
12 |
Correct |
30 ms |
13612 KB |
Output is correct |
13 |
Correct |
29 ms |
13680 KB |
Output is correct |
14 |
Correct |
28 ms |
13688 KB |
Output is correct |
15 |
Incorrect |
27 ms |
13764 KB |
Wrong Answer [6] |
16 |
Halted |
0 ms |
0 KB |
- |