#include <iostream>
#include <vector>
#include <queue>
#include <cassert>
#include <string>
#include <set>
using namespace std;
#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()
#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
const char nl = '\n';
const int mxN = 20010;
const int MOD = 1e9 + 7;
const long long infLL = 1e18;
int n, m, a, b, d[mxN];
vi U, V, adj[mxN], res; vpii g[mxN];
queue<int> q;
// set<string> good{"01001", "10110", "00110", "01101", "11010", "10100"};
vector<int> list = {0, 1, 0, 0, 1, 1};
int amt[3] = {0, 1, 2};
void dfs(int u, int cur_edge, int cur = 0){
if(cur_edge!=-1) res[cur_edge] = list[cur];
trav(v, g[u]){
if(cur_edge==v.s) continue;
if(siz(g[u]) == 2 && u != 0){
dfs(v.f, v.s, (cur+1)%6);
}
else{
dfs(v.f, v.s, list[cur]^1);
}
}
}
vi Mark(int N, int M, int A, int B, vi Uu, vi Vv){
U = Uu; V = Vv; n = N; m = M; a = A; b = B;
if(a==2){
res.resize(m);
// 0 -> 1 -> 0 -> 0 -> 1 -> 1 -> 0 -> 1 -> 0 -> 0 -> 1 -> 1
F0R(i, m){
g[U[i]].pb({V[i], i});
g[V[i]].pb({U[i], i});
}
dfs(0, -1, 0);
return res;
}
else{
res.resize(m);
F0R(i, n) d[i] = MOD;
F0R(i, m){
adj[U[i]].pb(V[i]);
adj[V[i]].pb(U[i]);
}
d[0] = 0;
q.push(0);
while(!q.empty()){
int u = q.front(); q.pop();
trav(v, adj[u]){
if(ckmin(d[v], d[u]+1)){
q.push(v);
}
}
}
F0R(i, m){
// we want to give them the value of the vertex with the higher value so that we know where to go
if(d[U[i]]<d[V[i]])
swap(U[i], V[i]);
if(d[U[i]]==d[V[i]]){
res[i] = amt[d[U[i]]%3];
}
else{
res[i] = amt[d[V[i]]%3];
// if we have distance 2 and 3
// we will at 3 see that we have 2
}
}
return res;
}
}
#ifdef ACMX
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int N, M, A, B; cin >> N >> M >> A >> B;
U.resize(M);
V.resize(M);
F0R(i, M){
cin >> U[i] >> V[i];
}
vi res = Mark(N, M, A, B, U, V);
trav(x, res){
cout << x << " ";
}
cout << nl;
return 0;
}
#endif
#include <vector>
#include <iostream>
#include <queue>
#include <cassert>
#include <set>
#include <algorithm>
using namespace std;
#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()
#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
const char nl = '\n';
const int mxN = 2e5 + 10;
const int MOD = 1e9 + 7;
const long long infLL = 1e18;
vector<int> list = {0, 1, 0, 0, 1, 1};
vector<int> cur;
vector<int> seen;
int a, b; int choose = 0, last = -1, going_up =0;
set<vector<int>> lists {
{1,1,0,0,1},
{1,0,0,1,0},
{0,0,1,0,1},
{0,1,0,1,1},
{1,0,1,1,0},
{0,1,1,0,0},
};
int lst = -1;
void Init(int A, int B){
a = A, b = B;
}
int Move(vi y){
if(a > 2){
if(y[0] == 0 && y[1] == 0 && y[2] == 0){
assert(false);
}
else if(y[0] == 0 && y[1] == 0){
return 2;
}
else if(y[1] == 0 && y[2] == 0){
return 0;
}
else if(y[2] == 0 && y[0] == 0){
return 1;
}
else if(y[0] == 0){
return 1;
}
else if(y[1] == 0){
return 2;
}
else if(y[2] == 0){
return 0;
}
else{
assert(false);
}
}
else{
int A = a;
int B = b;
vector<int> new_y = y;
if (~last) new_y[last]++;
int deg = new_y[0] + new_y[1];
if (deg != 2) going_up = true;
if (going_up) {
if (deg == 1) {
if (last == -1) FOR(i, 0, A) if (y[i]) return last = i;
return -1;
} else if (deg == 2) {
FOR(i, 0, A) if (y[i]) return last = i;
} else {
FOR(i, 0, A) if (new_y[i] == 1) {
if (!y[i]) return -1;
return last = i;
}
}
} else {
if (~last) {
FOR(i, 0, A) if (y[i]) {
seen.push_back(i);
if (seen.size() < 5) return last = i;
else {
going_up = true;
for (vector<int> v : lists)
if (v == seen) return last = i;
return -1;
}
}
} else {
FOR(i, 0, A) if (y[i]) {
seen.push_back(i);
y[i]--;
FOR(j, 0, A) if (y[j]) {
seen.push_back(j);
return last = j;
}
}
}
}
}
}
#ifdef ACMX
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
return 0;
}
#endif
Compilation message
Catherine.cpp: In function 'int Move(vi)':
Catherine.cpp:84:13: warning: unused variable 'B' [-Wunused-variable]
84 | int B = b;
| ^
Catherine.cpp:127:1: warning: control reaches end of non-void function [-Wreturn-type]
127 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
16292 KB |
Output is correct |
2 |
Correct |
1 ms |
2560 KB |
Output is correct |
3 |
Correct |
41 ms |
15600 KB |
Output is correct |
4 |
Correct |
68 ms |
17452 KB |
Output is correct |
5 |
Correct |
70 ms |
17580 KB |
Output is correct |
6 |
Correct |
51 ms |
16024 KB |
Output is correct |
7 |
Correct |
52 ms |
16212 KB |
Output is correct |
8 |
Correct |
59 ms |
16800 KB |
Output is correct |
9 |
Correct |
60 ms |
16892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
16292 KB |
Output is correct |
2 |
Correct |
1 ms |
2560 KB |
Output is correct |
3 |
Correct |
41 ms |
15600 KB |
Output is correct |
4 |
Correct |
68 ms |
17452 KB |
Output is correct |
5 |
Correct |
70 ms |
17580 KB |
Output is correct |
6 |
Correct |
51 ms |
16024 KB |
Output is correct |
7 |
Correct |
52 ms |
16212 KB |
Output is correct |
8 |
Correct |
59 ms |
16800 KB |
Output is correct |
9 |
Correct |
60 ms |
16892 KB |
Output is correct |
10 |
Correct |
45 ms |
14192 KB |
Output is correct |
11 |
Correct |
46 ms |
14308 KB |
Output is correct |
12 |
Correct |
44 ms |
14324 KB |
Output is correct |
13 |
Correct |
45 ms |
14328 KB |
Output is correct |
14 |
Correct |
46 ms |
14480 KB |
Output is correct |
15 |
Correct |
53 ms |
15056 KB |
Output is correct |
16 |
Correct |
57 ms |
16892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
13876 KB |
Output is correct |
2 |
Correct |
1 ms |
2560 KB |
Output is correct |
3 |
Correct |
39 ms |
13308 KB |
Output is correct |
4 |
Correct |
61 ms |
15280 KB |
Output is correct |
5 |
Correct |
62 ms |
15284 KB |
Output is correct |
6 |
Correct |
48 ms |
13836 KB |
Output is correct |
7 |
Correct |
49 ms |
13692 KB |
Output is correct |
8 |
Correct |
56 ms |
14620 KB |
Output is correct |
9 |
Correct |
59 ms |
14504 KB |
Output is correct |
10 |
Correct |
52 ms |
14376 KB |
Output is correct |
11 |
Correct |
51 ms |
14380 KB |
Output is correct |
12 |
Correct |
53 ms |
14204 KB |
Output is correct |
13 |
Correct |
52 ms |
14380 KB |
Output is correct |
14 |
Correct |
57 ms |
14620 KB |
Output is correct |
15 |
Correct |
60 ms |
14624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
13876 KB |
Output is correct |
2 |
Correct |
1 ms |
2560 KB |
Output is correct |
3 |
Correct |
39 ms |
13308 KB |
Output is correct |
4 |
Correct |
61 ms |
15280 KB |
Output is correct |
5 |
Correct |
62 ms |
15284 KB |
Output is correct |
6 |
Correct |
48 ms |
13836 KB |
Output is correct |
7 |
Correct |
49 ms |
13692 KB |
Output is correct |
8 |
Correct |
56 ms |
14620 KB |
Output is correct |
9 |
Correct |
59 ms |
14504 KB |
Output is correct |
10 |
Correct |
52 ms |
14376 KB |
Output is correct |
11 |
Correct |
51 ms |
14380 KB |
Output is correct |
12 |
Correct |
53 ms |
14204 KB |
Output is correct |
13 |
Correct |
52 ms |
14380 KB |
Output is correct |
14 |
Correct |
57 ms |
14620 KB |
Output is correct |
15 |
Correct |
60 ms |
14624 KB |
Output is correct |
16 |
Correct |
41 ms |
12152 KB |
Output is correct |
17 |
Correct |
42 ms |
12320 KB |
Output is correct |
18 |
Correct |
43 ms |
12280 KB |
Output is correct |
19 |
Correct |
44 ms |
12388 KB |
Output is correct |
20 |
Correct |
52 ms |
12808 KB |
Output is correct |
21 |
Correct |
50 ms |
12536 KB |
Output is correct |
22 |
Correct |
55 ms |
14776 KB |
Output is correct |
23 |
Correct |
44 ms |
12508 KB |
Output is correct |
24 |
Correct |
44 ms |
12272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2560 KB |
Output is correct |
2 |
Correct |
1 ms |
2560 KB |
Output is correct |
3 |
Correct |
3 ms |
2560 KB |
Output is correct |
4 |
Correct |
2 ms |
2560 KB |
Output is correct |
5 |
Correct |
2 ms |
2560 KB |
Output is correct |
6 |
Correct |
2 ms |
2560 KB |
Output is correct |
7 |
Correct |
2 ms |
2560 KB |
Output is correct |
8 |
Correct |
2 ms |
2560 KB |
Output is correct |
9 |
Correct |
2 ms |
2560 KB |
Output is correct |
10 |
Correct |
3 ms |
2560 KB |
Output is correct |
11 |
Correct |
3 ms |
2560 KB |
Output is correct |
12 |
Correct |
2 ms |
2560 KB |
Output is correct |
13 |
Correct |
2 ms |
2560 KB |
Output is correct |
14 |
Correct |
2 ms |
2560 KB |
Output is correct |
15 |
Correct |
2 ms |
2560 KB |
Output is correct |
16 |
Correct |
2 ms |
2560 KB |
Output is correct |
17 |
Correct |
2 ms |
2560 KB |
Output is correct |
18 |
Correct |
2 ms |
2560 KB |
Output is correct |
19 |
Correct |
2 ms |
2560 KB |
Output is correct |
20 |
Correct |
2 ms |
2560 KB |
Output is correct |
21 |
Correct |
2 ms |
2560 KB |
Output is correct |
22 |
Correct |
2 ms |
2560 KB |
Output is correct |
23 |
Correct |
2 ms |
2560 KB |
Output is correct |
24 |
Correct |
2 ms |
2560 KB |
Output is correct |
25 |
Correct |
3 ms |
2560 KB |
Output is correct |
26 |
Correct |
2 ms |
2560 KB |
Output is correct |
27 |
Correct |
2 ms |
2560 KB |
Output is correct |
28 |
Correct |
2 ms |
2560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
12148 KB |
Output is correct |
2 |
Correct |
52 ms |
13320 KB |
Output is correct |
3 |
Correct |
1 ms |
2560 KB |
Output is correct |
4 |
Correct |
38 ms |
11964 KB |
Output is correct |
5 |
Correct |
64 ms |
14808 KB |
Output is correct |
6 |
Correct |
60 ms |
14844 KB |
Output is correct |
7 |
Correct |
49 ms |
14048 KB |
Output is correct |
8 |
Correct |
47 ms |
14028 KB |
Output is correct |
9 |
Correct |
59 ms |
15052 KB |
Output is correct |
10 |
Correct |
59 ms |
15068 KB |
Output is correct |
11 |
Correct |
62 ms |
15060 KB |
Output is correct |
12 |
Correct |
60 ms |
15188 KB |
Output is correct |
13 |
Correct |
60 ms |
15188 KB |
Output is correct |
14 |
Correct |
60 ms |
15196 KB |
Output is correct |
15 |
Correct |
75 ms |
15200 KB |
Output is correct |
16 |
Correct |
57 ms |
15196 KB |
Output is correct |
17 |
Correct |
55 ms |
14808 KB |
Output is correct |
18 |
Correct |
60 ms |
14804 KB |
Output is correct |
19 |
Correct |
57 ms |
14800 KB |
Output is correct |
20 |
Correct |
55 ms |
14816 KB |
Output is correct |
21 |
Correct |
55 ms |
14800 KB |
Output is correct |
22 |
Correct |
60 ms |
14796 KB |
Output is correct |
23 |
Correct |
43 ms |
12428 KB |
Output is correct |
24 |
Correct |
44 ms |
12516 KB |
Output is correct |
25 |
Correct |
46 ms |
12884 KB |
Output is correct |
26 |
Correct |
46 ms |
12748 KB |
Output is correct |
27 |
Correct |
54 ms |
13952 KB |
Output is correct |
28 |
Correct |
53 ms |
13972 KB |
Output is correct |
29 |
Correct |
52 ms |
13772 KB |
Output is correct |
30 |
Correct |
56 ms |
13776 KB |
Output is correct |
31 |
Correct |
45 ms |
12532 KB |
Output is correct |
32 |
Correct |
49 ms |
12492 KB |
Output is correct |
33 |
Correct |
45 ms |
13132 KB |
Output is correct |
34 |
Correct |
45 ms |
13004 KB |
Output is correct |
35 |
Correct |
52 ms |
13708 KB |
Output is correct |
36 |
Correct |
51 ms |
13772 KB |
Output is correct |
37 |
Correct |
52 ms |
13976 KB |
Output is correct |
38 |
Correct |
53 ms |
13772 KB |
Output is correct |
39 |
Correct |
52 ms |
13644 KB |
Output is correct |
40 |
Correct |
54 ms |
13668 KB |
Output is correct |
41 |
Correct |
62 ms |
14444 KB |
Output is correct |
42 |
Correct |
60 ms |
14324 KB |
Output is correct |
43 |
Correct |
57 ms |
14328 KB |
Output is correct |
44 |
Correct |
56 ms |
14324 KB |
Output is correct |
45 |
Correct |
55 ms |
14468 KB |
Output is correct |
46 |
Correct |
54 ms |
14464 KB |
Output is correct |
47 |
Correct |
50 ms |
13604 KB |
Output is correct |
48 |
Correct |
51 ms |
13860 KB |
Output is correct |
49 |
Correct |
51 ms |
13480 KB |
Output is correct |
50 |
Correct |
50 ms |
13736 KB |
Output is correct |
51 |
Correct |
45 ms |
12676 KB |
Output is correct |
52 |
Correct |
45 ms |
12676 KB |
Output is correct |
53 |
Correct |
49 ms |
12868 KB |
Output is correct |
54 |
Correct |
45 ms |
12628 KB |
Output is correct |
55 |
Correct |
46 ms |
12860 KB |
Output is correct |
56 |
Correct |
47 ms |
12756 KB |
Output is correct |
57 |
Correct |
48 ms |
12756 KB |
Output is correct |
58 |
Correct |
46 ms |
12636 KB |
Output is correct |
59 |
Correct |
46 ms |
12500 KB |
Output is correct |
60 |
Correct |
48 ms |
12640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
12256 KB |
Output is correct |
2 |
Correct |
50 ms |
13068 KB |
Output is correct |
3 |
Correct |
1 ms |
2624 KB |
Output is correct |
4 |
Correct |
39 ms |
12104 KB |
Output is correct |
5 |
Correct |
64 ms |
14928 KB |
Output is correct |
6 |
Correct |
59 ms |
14708 KB |
Output is correct |
7 |
Correct |
46 ms |
13884 KB |
Output is correct |
8 |
Correct |
46 ms |
14056 KB |
Output is correct |
9 |
Correct |
59 ms |
15128 KB |
Output is correct |
10 |
Correct |
59 ms |
15092 KB |
Output is correct |
11 |
Correct |
61 ms |
14940 KB |
Output is correct |
12 |
Correct |
66 ms |
14916 KB |
Output is correct |
13 |
Correct |
60 ms |
15060 KB |
Output is correct |
14 |
Correct |
64 ms |
14936 KB |
Output is correct |
15 |
Correct |
59 ms |
14720 KB |
Output is correct |
16 |
Correct |
65 ms |
15060 KB |
Output is correct |
17 |
Correct |
57 ms |
14960 KB |
Output is correct |
18 |
Correct |
60 ms |
14796 KB |
Output is correct |
19 |
Correct |
56 ms |
15060 KB |
Output is correct |
20 |
Correct |
55 ms |
14764 KB |
Output is correct |
21 |
Correct |
56 ms |
14676 KB |
Output is correct |
22 |
Correct |
59 ms |
14800 KB |
Output is correct |
23 |
Correct |
48 ms |
12364 KB |
Output is correct |
24 |
Correct |
43 ms |
12520 KB |
Output is correct |
25 |
Correct |
45 ms |
12752 KB |
Output is correct |
26 |
Correct |
46 ms |
12880 KB |
Output is correct |
27 |
Correct |
51 ms |
13900 KB |
Output is correct |
28 |
Correct |
53 ms |
13968 KB |
Output is correct |
29 |
Correct |
52 ms |
13964 KB |
Output is correct |
30 |
Correct |
52 ms |
13960 KB |
Output is correct |
31 |
Correct |
44 ms |
12532 KB |
Output is correct |
32 |
Correct |
46 ms |
12492 KB |
Output is correct |
33 |
Correct |
47 ms |
13128 KB |
Output is correct |
34 |
Correct |
46 ms |
13124 KB |
Output is correct |
35 |
Correct |
52 ms |
13652 KB |
Output is correct |
36 |
Correct |
54 ms |
13664 KB |
Output is correct |
37 |
Correct |
51 ms |
13900 KB |
Output is correct |
38 |
Correct |
54 ms |
13784 KB |
Output is correct |
39 |
Correct |
52 ms |
13676 KB |
Output is correct |
40 |
Correct |
52 ms |
13892 KB |
Output is correct |
41 |
Correct |
55 ms |
14328 KB |
Output is correct |
42 |
Correct |
54 ms |
14332 KB |
Output is correct |
43 |
Correct |
57 ms |
14412 KB |
Output is correct |
44 |
Correct |
54 ms |
14560 KB |
Output is correct |
45 |
Correct |
54 ms |
14460 KB |
Output is correct |
46 |
Correct |
56 ms |
14468 KB |
Output is correct |
47 |
Correct |
53 ms |
13596 KB |
Output is correct |
48 |
Correct |
50 ms |
13588 KB |
Output is correct |
49 |
Correct |
49 ms |
13608 KB |
Output is correct |
50 |
Correct |
51 ms |
13652 KB |
Output is correct |
51 |
Correct |
46 ms |
13120 KB |
Output is correct |
52 |
Correct |
46 ms |
12868 KB |
Output is correct |
53 |
Correct |
45 ms |
12756 KB |
Output is correct |
54 |
Correct |
45 ms |
12732 KB |
Output is correct |
55 |
Correct |
45 ms |
12856 KB |
Output is correct |
56 |
Correct |
48 ms |
12856 KB |
Output is correct |
57 |
Correct |
45 ms |
12768 KB |
Output is correct |
58 |
Correct |
45 ms |
12640 KB |
Output is correct |
59 |
Correct |
45 ms |
12652 KB |
Output is correct |
60 |
Correct |
45 ms |
12652 KB |
Output is correct |