#include"bits/stdc++.h"
#include"Anthony.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
namespace sol1{
vector<int> a = {0, 0, 1, 0, 1, 1};
vector<pair<int,int>> e[100000];
vector<int> ret;
void dfs(int n, int p, int b, int k){
//cout << n << " " << p << " " << b << " " << k << endl;
rep(i, e[n].size()){
if(e[n][i].first == p) continue;
if(e[n].size() >= 3){
if(b == 0){
ret[e[n][i].second] = 1;
dfs(e[n][i].first, n, 1, 2);
}
else{
ret[e[n][i].second] = 0;
dfs(e[n][i].first, n, 0, 0);
}
}
if(e[n].size() == 2){
ret[e[n][i].second] = a[(k+1)%6];
dfs(e[n][i].first, n, a[(k+1)%6], k+1);
}
}
}
vector<int> Mark1(int N, int M, int A, int B, vector<int> U, vector<int> V){
for(int i=0; i<M; i++){
e[U[i]].push_back({V[i], i});
e[V[i]].push_back({U[i], i});
ret.push_back(-1);
}
e[0].pb({-1,-1});
dfs(0, -1, 1, 0);
rep(i, M){
//cout << i << " " << ret[i] << endl;
}
return ret;
}
} // namespace
namespace sol2{
vector<pair<int,int>> e[100000];
int cost[100000];
queue<int> que;
vector<int> ret;
vector<int> Mark2(int N, int M, int A, int B, vector<int> U, vector<int> V){
for(int i=0; i<M; i++){
e[U[i]].push_back({V[i], i});
e[V[i]].push_back({U[i], i});
ret.push_back(3);
}
for(int i=0; i<N; i++){
cost[i] = INT_MAX;
}
cost[0] = 0;
que.push(0);
while(!que.empty()){
int n = que.front();
que.pop();
for(int i=0; i<e[n].size(); i++){
if(cost[e[n][i].first] > cost[n]+1){
cost[e[n][i].first] = cost[n]+1;
que.push(e[n][i].first);
}
}
}
for(int i=0; i<M; i++){
if(cost[U[i]]+1 == cost[V[i]]) ret[i] = cost[U[i]] % 3;
if(cost[U[i]] == cost[V[i]]+1) ret[i] = cost[V[i]] % 3;
if(cost[U[i]] == cost[V[i]]) ret[i] = cost[U[i]] % 3;
}
return ret;
}
} // namespace
vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V){
if(A == 2) return sol1::Mark1(N, M, A, B, U, V);
return sol2::Mark2(N, M, A, B, U, V);
}
#include"bits/stdc++.h"
#include"Catherine.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
namespace sola{
vector<int> a = {0, 0, 1, 0, 1, 1};
int A, B;
bool flg = false;
vector<int> st;
int b = -1;
int Move1(vector<int> y){
//cout << b << " " << flg << " " << y[0] << " " << y[1] << endl;
if(flg){
// -o-
if(y[0]+y[1]+1 == 2){
if(y[0] == 0) return b = 1;
if(y[1] == 0) return b = 0;
}
// -o<
if(y[0]+y[1]+1 > 2){
return b = b^1;
}
assert(false);
}
// -o<
if(b != -1) y[b]++;
if(y[0]+y[1] > 2){
flg = true;
if(y[0] == 1){
if(b == 0) return -1;
return b = 0;
}
if(y[1] == 1){
if(b == 1) return -1;
return b = 1;
}
}
// -o
if(y[0] == 0 && y[1] == 1){
flg = true;
if(b == -1) return b = 1;
b = 1;
return -1;
}
if(y[1] == 0 && y[0] == 1){
flg = true;
if(b == -1) return b = 0;
b = 0;
return -1;
}
// -o-
if(b != -1) y[b]--;
if(b == -1){
if(y[0] == 2){
st.pb(0);
st.pb(0);
return b = 0;
}
if(y[1] == 2){
st.pb(1);
st.pb(1);
return b = 1;
}
st.pb(0);
st.pb(1);
return b = 1;
}
else{
if(y[0] == 1) st.pb(0);
if(y[1] == 1) st.pb(1);
if(st.size() == 5){
flg = true;
bool ok = true;
rep(j, 6){
bool same = true;
rep(k, 5){
same = same & (st[k] == a[(j+k)%6]);
}
if(same) ok = false;
}
//if(ok) cout << "ok" << endl;
//else cout << "ng" << endl;
if(ok) return b = st[4];
else{
b = st[3];
//cout << "return -1" << endl;
return -1;
}
}
else{
return b = st.back();
}
}
}
} // namespace
namespace solb{
int Move2(vector<int> y){
if(y[0] > 0 && y[1] >= 0 && y[2] == 0) return 0;
if(y[1] > 0 && y[2] >= 0 && y[0] == 0) return 1;
if(y[2] > 0 && y[0] >= 0 && y[1] == 0) return 2;
}
} // namespace
void Init(int A, int B){
sola::A = A;
sola::B = B;
}
int Move(vector<int> y){
if(sola::A == 2) return sola::Move1(y);
return solb::Move2(y);
}
Compilation message
Anthony.cpp: In function 'void sol1::dfs(int, int, int, int)':
Anthony.cpp:9:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
9 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
| ^
Anthony.cpp:22:3: note: in expansion of macro 'rep'
22 | rep(i, e[n].size()){
| ^~~
Anthony.cpp: In function 'std::vector<int> sol1::Mark1(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:9:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
9 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
| ^
Anthony.cpp:50:3: note: in expansion of macro 'rep'
50 | rep(i, M){
| ^~~
Anthony.cpp: In function 'std::vector<int> sol2::Mark2(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for(int i=0; i<e[n].size(); i++){
| ~^~~~~~~~~~~~
Catherine.cpp: In function 'int sola::Move1(std::vector<int>)':
Catherine.cpp:9:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
9 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
| ^
Catherine.cpp:86:5: note: in expansion of macro 'rep'
86 | rep(j, 6){
| ^~~
Catherine.cpp:9:27: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
9 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
| ^
Catherine.cpp:88:6: note: in expansion of macro 'rep'
88 | rep(k, 5){
| ^~~
Catherine.cpp: In function 'int solb::Move2(std::vector<int>)':
Catherine.cpp:116:2: warning: control reaches end of non-void function [-Wreturn-type]
116 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
20336 KB |
Output is correct |
2 |
Correct |
4 ms |
5300 KB |
Output is correct |
3 |
Correct |
41 ms |
19644 KB |
Output is correct |
4 |
Correct |
57 ms |
21360 KB |
Output is correct |
5 |
Correct |
61 ms |
21340 KB |
Output is correct |
6 |
Correct |
51 ms |
20060 KB |
Output is correct |
7 |
Correct |
50 ms |
19956 KB |
Output is correct |
8 |
Correct |
53 ms |
20704 KB |
Output is correct |
9 |
Correct |
54 ms |
20808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
20336 KB |
Output is correct |
2 |
Correct |
4 ms |
5300 KB |
Output is correct |
3 |
Correct |
41 ms |
19644 KB |
Output is correct |
4 |
Correct |
57 ms |
21360 KB |
Output is correct |
5 |
Correct |
61 ms |
21340 KB |
Output is correct |
6 |
Correct |
51 ms |
20060 KB |
Output is correct |
7 |
Correct |
50 ms |
19956 KB |
Output is correct |
8 |
Correct |
53 ms |
20704 KB |
Output is correct |
9 |
Correct |
54 ms |
20808 KB |
Output is correct |
10 |
Correct |
41 ms |
18028 KB |
Output is correct |
11 |
Correct |
45 ms |
18212 KB |
Output is correct |
12 |
Correct |
43 ms |
18304 KB |
Output is correct |
13 |
Correct |
43 ms |
18088 KB |
Output is correct |
14 |
Correct |
44 ms |
18504 KB |
Output is correct |
15 |
Correct |
50 ms |
18784 KB |
Output is correct |
16 |
Correct |
53 ms |
20976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
17992 KB |
Output is correct |
2 |
Correct |
4 ms |
5236 KB |
Output is correct |
3 |
Correct |
38 ms |
17412 KB |
Output is correct |
4 |
Correct |
55 ms |
19204 KB |
Output is correct |
5 |
Correct |
67 ms |
19108 KB |
Output is correct |
6 |
Correct |
49 ms |
17920 KB |
Output is correct |
7 |
Correct |
44 ms |
17940 KB |
Output is correct |
8 |
Correct |
51 ms |
18448 KB |
Output is correct |
9 |
Correct |
51 ms |
18440 KB |
Output is correct |
10 |
Correct |
48 ms |
18364 KB |
Output is correct |
11 |
Correct |
50 ms |
18360 KB |
Output is correct |
12 |
Correct |
47 ms |
18204 KB |
Output is correct |
13 |
Correct |
46 ms |
18224 KB |
Output is correct |
14 |
Correct |
53 ms |
18456 KB |
Output is correct |
15 |
Correct |
52 ms |
18460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
17992 KB |
Output is correct |
2 |
Correct |
4 ms |
5236 KB |
Output is correct |
3 |
Correct |
38 ms |
17412 KB |
Output is correct |
4 |
Correct |
55 ms |
19204 KB |
Output is correct |
5 |
Correct |
67 ms |
19108 KB |
Output is correct |
6 |
Correct |
49 ms |
17920 KB |
Output is correct |
7 |
Correct |
44 ms |
17940 KB |
Output is correct |
8 |
Correct |
51 ms |
18448 KB |
Output is correct |
9 |
Correct |
51 ms |
18440 KB |
Output is correct |
10 |
Correct |
48 ms |
18364 KB |
Output is correct |
11 |
Correct |
50 ms |
18360 KB |
Output is correct |
12 |
Correct |
47 ms |
18204 KB |
Output is correct |
13 |
Correct |
46 ms |
18224 KB |
Output is correct |
14 |
Correct |
53 ms |
18456 KB |
Output is correct |
15 |
Correct |
52 ms |
18460 KB |
Output is correct |
16 |
Correct |
39 ms |
16340 KB |
Output is correct |
17 |
Correct |
41 ms |
16316 KB |
Output is correct |
18 |
Correct |
45 ms |
16368 KB |
Output is correct |
19 |
Correct |
41 ms |
16232 KB |
Output is correct |
20 |
Correct |
45 ms |
16916 KB |
Output is correct |
21 |
Correct |
44 ms |
16808 KB |
Output is correct |
22 |
Correct |
53 ms |
18668 KB |
Output is correct |
23 |
Correct |
45 ms |
16332 KB |
Output is correct |
24 |
Correct |
54 ms |
16312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5492 KB |
Output is correct |
2 |
Correct |
5 ms |
5236 KB |
Output is correct |
3 |
Correct |
5 ms |
5492 KB |
Output is correct |
4 |
Correct |
5 ms |
5552 KB |
Output is correct |
5 |
Correct |
5 ms |
5636 KB |
Output is correct |
6 |
Correct |
5 ms |
5624 KB |
Output is correct |
7 |
Correct |
5 ms |
5576 KB |
Output is correct |
8 |
Correct |
5 ms |
5624 KB |
Output is correct |
9 |
Correct |
6 ms |
5624 KB |
Output is correct |
10 |
Correct |
5 ms |
5604 KB |
Output is correct |
11 |
Correct |
5 ms |
5548 KB |
Output is correct |
12 |
Correct |
5 ms |
5504 KB |
Output is correct |
13 |
Correct |
5 ms |
5496 KB |
Output is correct |
14 |
Correct |
5 ms |
5564 KB |
Output is correct |
15 |
Correct |
5 ms |
5496 KB |
Output is correct |
16 |
Correct |
6 ms |
5496 KB |
Output is correct |
17 |
Correct |
5 ms |
5560 KB |
Output is correct |
18 |
Correct |
6 ms |
5508 KB |
Output is correct |
19 |
Correct |
6 ms |
5496 KB |
Output is correct |
20 |
Correct |
5 ms |
5496 KB |
Output is correct |
21 |
Correct |
5 ms |
5496 KB |
Output is correct |
22 |
Correct |
5 ms |
5496 KB |
Output is correct |
23 |
Correct |
6 ms |
5556 KB |
Output is correct |
24 |
Correct |
5 ms |
5496 KB |
Output is correct |
25 |
Correct |
5 ms |
5496 KB |
Output is correct |
26 |
Correct |
5 ms |
5500 KB |
Output is correct |
27 |
Correct |
5 ms |
5552 KB |
Output is correct |
28 |
Correct |
5 ms |
5508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
15952 KB |
Output is correct |
2 |
Correct |
65 ms |
17112 KB |
Output is correct |
3 |
Correct |
5 ms |
5236 KB |
Output is correct |
4 |
Correct |
43 ms |
15736 KB |
Output is correct |
5 |
Correct |
67 ms |
18668 KB |
Output is correct |
6 |
Correct |
61 ms |
18740 KB |
Output is correct |
7 |
Correct |
46 ms |
17684 KB |
Output is correct |
8 |
Correct |
49 ms |
17836 KB |
Output is correct |
9 |
Correct |
61 ms |
18612 KB |
Output is correct |
10 |
Correct |
60 ms |
18696 KB |
Output is correct |
11 |
Correct |
55 ms |
18648 KB |
Output is correct |
12 |
Correct |
66 ms |
18748 KB |
Output is correct |
13 |
Correct |
62 ms |
18604 KB |
Output is correct |
14 |
Correct |
63 ms |
18600 KB |
Output is correct |
15 |
Correct |
59 ms |
18692 KB |
Output is correct |
16 |
Correct |
63 ms |
18668 KB |
Output is correct |
17 |
Correct |
56 ms |
18316 KB |
Output is correct |
18 |
Correct |
59 ms |
18340 KB |
Output is correct |
19 |
Correct |
53 ms |
18396 KB |
Output is correct |
20 |
Correct |
49 ms |
18412 KB |
Output is correct |
21 |
Correct |
54 ms |
18400 KB |
Output is correct |
22 |
Correct |
54 ms |
18324 KB |
Output is correct |
23 |
Correct |
48 ms |
15992 KB |
Output is correct |
24 |
Correct |
42 ms |
15928 KB |
Output is correct |
25 |
Correct |
50 ms |
16500 KB |
Output is correct |
26 |
Correct |
52 ms |
16436 KB |
Output is correct |
27 |
Correct |
53 ms |
17328 KB |
Output is correct |
28 |
Correct |
51 ms |
17168 KB |
Output is correct |
29 |
Correct |
50 ms |
17248 KB |
Output is correct |
30 |
Correct |
50 ms |
17348 KB |
Output is correct |
31 |
Correct |
42 ms |
15920 KB |
Output is correct |
32 |
Correct |
42 ms |
15932 KB |
Output is correct |
33 |
Correct |
51 ms |
16268 KB |
Output is correct |
34 |
Correct |
43 ms |
16380 KB |
Output is correct |
35 |
Correct |
50 ms |
17136 KB |
Output is correct |
36 |
Correct |
49 ms |
17200 KB |
Output is correct |
37 |
Correct |
47 ms |
17136 KB |
Output is correct |
38 |
Correct |
48 ms |
17184 KB |
Output is correct |
39 |
Correct |
47 ms |
17096 KB |
Output is correct |
40 |
Correct |
49 ms |
17172 KB |
Output is correct |
41 |
Correct |
50 ms |
17784 KB |
Output is correct |
42 |
Correct |
50 ms |
17876 KB |
Output is correct |
43 |
Correct |
51 ms |
17900 KB |
Output is correct |
44 |
Correct |
51 ms |
17764 KB |
Output is correct |
45 |
Correct |
50 ms |
17856 KB |
Output is correct |
46 |
Correct |
53 ms |
17768 KB |
Output is correct |
47 |
Correct |
48 ms |
16860 KB |
Output is correct |
48 |
Correct |
49 ms |
17064 KB |
Output is correct |
49 |
Correct |
47 ms |
16804 KB |
Output is correct |
50 |
Correct |
47 ms |
16984 KB |
Output is correct |
51 |
Correct |
44 ms |
16024 KB |
Output is correct |
52 |
Correct |
43 ms |
16128 KB |
Output is correct |
53 |
Correct |
43 ms |
16064 KB |
Output is correct |
54 |
Correct |
43 ms |
16084 KB |
Output is correct |
55 |
Correct |
45 ms |
16024 KB |
Output is correct |
56 |
Correct |
51 ms |
16116 KB |
Output is correct |
57 |
Correct |
43 ms |
16084 KB |
Output is correct |
58 |
Correct |
46 ms |
16160 KB |
Output is correct |
59 |
Correct |
46 ms |
16304 KB |
Output is correct |
60 |
Correct |
43 ms |
16264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
15920 KB |
Output is correct |
2 |
Correct |
47 ms |
17004 KB |
Output is correct |
3 |
Correct |
5 ms |
5236 KB |
Output is correct |
4 |
Correct |
37 ms |
15664 KB |
Output is correct |
5 |
Correct |
54 ms |
18668 KB |
Output is correct |
6 |
Correct |
54 ms |
18704 KB |
Output is correct |
7 |
Correct |
46 ms |
17796 KB |
Output is correct |
8 |
Correct |
46 ms |
17848 KB |
Output is correct |
9 |
Correct |
71 ms |
18644 KB |
Output is correct |
10 |
Correct |
74 ms |
18736 KB |
Output is correct |
11 |
Correct |
62 ms |
18684 KB |
Output is correct |
12 |
Correct |
52 ms |
18676 KB |
Output is correct |
13 |
Correct |
55 ms |
18708 KB |
Output is correct |
14 |
Correct |
56 ms |
18688 KB |
Output is correct |
15 |
Correct |
74 ms |
18712 KB |
Output is correct |
16 |
Correct |
63 ms |
18628 KB |
Output is correct |
17 |
Correct |
63 ms |
18420 KB |
Output is correct |
18 |
Correct |
61 ms |
18300 KB |
Output is correct |
19 |
Correct |
64 ms |
18396 KB |
Output is correct |
20 |
Correct |
68 ms |
18284 KB |
Output is correct |
21 |
Correct |
67 ms |
18328 KB |
Output is correct |
22 |
Correct |
49 ms |
18372 KB |
Output is correct |
23 |
Correct |
50 ms |
15856 KB |
Output is correct |
24 |
Correct |
43 ms |
15832 KB |
Output is correct |
25 |
Correct |
43 ms |
16272 KB |
Output is correct |
26 |
Correct |
42 ms |
16492 KB |
Output is correct |
27 |
Correct |
50 ms |
17276 KB |
Output is correct |
28 |
Correct |
49 ms |
17344 KB |
Output is correct |
29 |
Correct |
48 ms |
17252 KB |
Output is correct |
30 |
Correct |
48 ms |
17256 KB |
Output is correct |
31 |
Correct |
41 ms |
15872 KB |
Output is correct |
32 |
Correct |
42 ms |
15892 KB |
Output is correct |
33 |
Correct |
50 ms |
16452 KB |
Output is correct |
34 |
Correct |
50 ms |
16448 KB |
Output is correct |
35 |
Correct |
48 ms |
17124 KB |
Output is correct |
36 |
Correct |
56 ms |
17128 KB |
Output is correct |
37 |
Correct |
53 ms |
17136 KB |
Output is correct |
38 |
Correct |
49 ms |
17104 KB |
Output is correct |
39 |
Correct |
50 ms |
17088 KB |
Output is correct |
40 |
Correct |
55 ms |
17148 KB |
Output is correct |
41 |
Correct |
56 ms |
17796 KB |
Output is correct |
42 |
Correct |
56 ms |
17752 KB |
Output is correct |
43 |
Correct |
59 ms |
17756 KB |
Output is correct |
44 |
Correct |
54 ms |
17860 KB |
Output is correct |
45 |
Correct |
54 ms |
17836 KB |
Output is correct |
46 |
Correct |
59 ms |
17876 KB |
Output is correct |
47 |
Correct |
51 ms |
16864 KB |
Output is correct |
48 |
Correct |
48 ms |
16820 KB |
Output is correct |
49 |
Correct |
47 ms |
16980 KB |
Output is correct |
50 |
Correct |
55 ms |
16992 KB |
Output is correct |
51 |
Correct |
44 ms |
16084 KB |
Output is correct |
52 |
Correct |
44 ms |
16092 KB |
Output is correct |
53 |
Correct |
44 ms |
16116 KB |
Output is correct |
54 |
Correct |
42 ms |
16092 KB |
Output is correct |
55 |
Correct |
42 ms |
16212 KB |
Output is correct |
56 |
Correct |
43 ms |
16056 KB |
Output is correct |
57 |
Correct |
44 ms |
16112 KB |
Output is correct |
58 |
Correct |
56 ms |
16000 KB |
Output is correct |
59 |
Correct |
44 ms |
16212 KB |
Output is correct |
60 |
Correct |
45 ms |
16232 KB |
Output is correct |