# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
426056 | 2021-06-13T13:22:42 Z | duality | From Hacks to Snitches (BOI21_watchmen) | C++11 | 6000 ms | 144092 KB |
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back typedef long long int LLI; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vpii; int readInt() { char c; int n = 0; while ((c=getchar()) < '0'); n = c-'0'; while ((c=getchar()) >= '0') n = n*10+c-'0'; return n; } vi adjList[250000]; int pos[250000]; pair<int,pii> p[250000]; bool comp(int a,int b) { return p[a] < p[b]; } vi dist[250000]; int done[250000],done2[250000]; priority_queue<pii> H; int main() { int i,j; int N,M,K; int u,v,l; scanf("%d %d",&N,&M); for (i = 0; i < M; i++) { u = readInt(); v = readInt(); u--,v--; adjList[u].pb(v); adjList[v].pb(u); } scanf("%d",&K); for (i = 0; i < K; i++) { scanf("%d",&l); for (j = 0; j < l; j++) scanf("%d",&v),p[v-1] = mp(l,mp(j,i)); } for (i = 0; i < N; i++) { if (p[i].first == 0) p[i].first = 1; dist[i].resize(p[i].first); fill(dist[i].begin(),dist[i].end(),-1); sort(adjList[i].begin(),adjList[i].end(),comp); while ((pos[i] < adjList[i].size()) && (p[adjList[i][pos[i]]].first <= 1)) pos[i]++; } dist[0][0] = 0,H.push(mp(0,0)); while (!H.empty()) { int u = H.top().second; int d = -H.top().first; H.pop(); if (d > dist[u][d % p[u].first]) continue; else if (u == N-1) { printf("%d\n",d); return 0; } i = 0; if (done2[u]) i = pos[u]; for (; i < adjList[u].size(); i++) { int v = adjList[u][i],t = d; for (j = 0; j < ((p[u].first == 1) ? p[v].first:1); j++) { if (done[v] && (p[u].first == 1)) break; int bad = 0; if (p[v].first != 1) { if (((d+1) % p[v].first) == p[v].second.first) bad = 1; if (((d % p[v].first) == p[v].second.first) && (p[u].second.second == p[v].second.second) \ && (p[u].second.first == ((p[v].second.first+1) % p[v].first))) bad = 1; } if (!bad) { if ((dist[v][(d+1) % p[v].first] == -1) || (d+1 < dist[v][(d+1) % p[v].first])) { dist[v][(d+1) % p[v].first] = d+1; H.push(mp(-(d+1),v)); } } d++; if ((p[u].first != 1) && ((d % p[u].first) == p[u].second.first)) break; } if ((p[u].first == 1) && (p[v].first != 1)) done[v] = 1; d = t; } done2[u] = 1; } printf("impossible\n"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 13136 KB | Output is correct |
2 | Correct | 97 ms | 20404 KB | Output is correct |
3 | Correct | 88 ms | 20024 KB | Output is correct |
4 | Correct | 118 ms | 20244 KB | Output is correct |
5 | Correct | 8 ms | 12108 KB | Output is correct |
6 | Correct | 82 ms | 20008 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 13244 KB | Output is correct |
2 | Correct | 102 ms | 20332 KB | Output is correct |
3 | Correct | 119 ms | 20036 KB | Output is correct |
4 | Correct | 122 ms | 20228 KB | Output is correct |
5 | Correct | 8 ms | 12080 KB | Output is correct |
6 | Correct | 88 ms | 20040 KB | Output is correct |
7 | Correct | 140 ms | 19520 KB | Output is correct |
8 | Correct | 105 ms | 19764 KB | Output is correct |
9 | Correct | 91 ms | 19528 KB | Output is correct |
10 | Correct | 94 ms | 20044 KB | Output is correct |
11 | Correct | 85 ms | 19820 KB | Output is correct |
12 | Correct | 125 ms | 19936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 13244 KB | Output is correct |
2 | Correct | 102 ms | 20332 KB | Output is correct |
3 | Correct | 119 ms | 20036 KB | Output is correct |
4 | Correct | 122 ms | 20228 KB | Output is correct |
5 | Correct | 8 ms | 12080 KB | Output is correct |
6 | Correct | 88 ms | 20040 KB | Output is correct |
7 | Correct | 140 ms | 19520 KB | Output is correct |
8 | Correct | 105 ms | 19764 KB | Output is correct |
9 | Correct | 91 ms | 19528 KB | Output is correct |
10 | Correct | 94 ms | 20044 KB | Output is correct |
11 | Correct | 85 ms | 19820 KB | Output is correct |
12 | Correct | 125 ms | 19936 KB | Output is correct |
13 | Correct | 23 ms | 13268 KB | Output is correct |
14 | Correct | 92 ms | 20332 KB | Output is correct |
15 | Correct | 130 ms | 20000 KB | Output is correct |
16 | Correct | 158 ms | 20192 KB | Output is correct |
17 | Correct | 9 ms | 12108 KB | Output is correct |
18 | Correct | 121 ms | 19984 KB | Output is correct |
19 | Correct | 109 ms | 19580 KB | Output is correct |
20 | Correct | 108 ms | 19780 KB | Output is correct |
21 | Correct | 80 ms | 19548 KB | Output is correct |
22 | Correct | 131 ms | 20036 KB | Output is correct |
23 | Correct | 111 ms | 19904 KB | Output is correct |
24 | Correct | 110 ms | 19812 KB | Output is correct |
25 | Correct | 2148 ms | 64660 KB | Output is correct |
26 | Correct | 2208 ms | 68896 KB | Output is correct |
27 | Correct | 2076 ms | 65488 KB | Output is correct |
28 | Correct | 1475 ms | 68764 KB | Output is correct |
29 | Correct | 2258 ms | 60604 KB | Output is correct |
30 | Correct | 2299 ms | 101608 KB | Output is correct |
31 | Correct | 2709 ms | 107516 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 13244 KB | Output is correct |
2 | Correct | 102 ms | 20332 KB | Output is correct |
3 | Correct | 119 ms | 20036 KB | Output is correct |
4 | Correct | 122 ms | 20228 KB | Output is correct |
5 | Correct | 8 ms | 12080 KB | Output is correct |
6 | Correct | 88 ms | 20040 KB | Output is correct |
7 | Correct | 140 ms | 19520 KB | Output is correct |
8 | Correct | 105 ms | 19764 KB | Output is correct |
9 | Correct | 91 ms | 19528 KB | Output is correct |
10 | Correct | 94 ms | 20044 KB | Output is correct |
11 | Correct | 85 ms | 19820 KB | Output is correct |
12 | Correct | 125 ms | 19936 KB | Output is correct |
13 | Correct | 23 ms | 13268 KB | Output is correct |
14 | Correct | 92 ms | 20332 KB | Output is correct |
15 | Correct | 130 ms | 20000 KB | Output is correct |
16 | Correct | 158 ms | 20192 KB | Output is correct |
17 | Correct | 9 ms | 12108 KB | Output is correct |
18 | Correct | 121 ms | 19984 KB | Output is correct |
19 | Correct | 109 ms | 19580 KB | Output is correct |
20 | Correct | 108 ms | 19780 KB | Output is correct |
21 | Correct | 80 ms | 19548 KB | Output is correct |
22 | Correct | 131 ms | 20036 KB | Output is correct |
23 | Correct | 111 ms | 19904 KB | Output is correct |
24 | Correct | 110 ms | 19812 KB | Output is correct |
25 | Correct | 2148 ms | 64660 KB | Output is correct |
26 | Correct | 2208 ms | 68896 KB | Output is correct |
27 | Correct | 2076 ms | 65488 KB | Output is correct |
28 | Correct | 1475 ms | 68764 KB | Output is correct |
29 | Correct | 2258 ms | 60604 KB | Output is correct |
30 | Correct | 2299 ms | 101608 KB | Output is correct |
31 | Correct | 2709 ms | 107516 KB | Output is correct |
32 | Correct | 24 ms | 13836 KB | Output is correct |
33 | Correct | 112 ms | 21480 KB | Output is correct |
34 | Correct | 109 ms | 21140 KB | Output is correct |
35 | Correct | 123 ms | 21316 KB | Output is correct |
36 | Correct | 8 ms | 12240 KB | Output is correct |
37 | Correct | 86 ms | 21152 KB | Output is correct |
38 | Correct | 152 ms | 20852 KB | Output is correct |
39 | Correct | 84 ms | 21124 KB | Output is correct |
40 | Correct | 77 ms | 20752 KB | Output is correct |
41 | Correct | 115 ms | 21208 KB | Output is correct |
42 | Correct | 115 ms | 21060 KB | Output is correct |
43 | Correct | 101 ms | 20952 KB | Output is correct |
44 | Correct | 2427 ms | 103308 KB | Output is correct |
45 | Correct | 2181 ms | 107316 KB | Output is correct |
46 | Correct | 2117 ms | 104120 KB | Output is correct |
47 | Correct | 1697 ms | 107448 KB | Output is correct |
48 | Correct | 2366 ms | 99580 KB | Output is correct |
49 | Correct | 2590 ms | 101524 KB | Output is correct |
50 | Correct | 2847 ms | 107320 KB | Output is correct |
51 | Correct | 3376 ms | 111608 KB | Output is correct |
52 | Correct | 3917 ms | 122404 KB | Output is correct |
53 | Correct | 3343 ms | 121044 KB | Output is correct |
54 | Correct | 1710 ms | 98712 KB | Output is correct |
55 | Execution timed out | 6058 ms | 144092 KB | Time limit exceeded |
56 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 13136 KB | Output is correct |
2 | Correct | 97 ms | 20404 KB | Output is correct |
3 | Correct | 88 ms | 20024 KB | Output is correct |
4 | Correct | 118 ms | 20244 KB | Output is correct |
5 | Correct | 8 ms | 12108 KB | Output is correct |
6 | Correct | 82 ms | 20008 KB | Output is correct |
7 | Correct | 23 ms | 13244 KB | Output is correct |
8 | Correct | 102 ms | 20332 KB | Output is correct |
9 | Correct | 119 ms | 20036 KB | Output is correct |
10 | Correct | 122 ms | 20228 KB | Output is correct |
11 | Correct | 8 ms | 12080 KB | Output is correct |
12 | Correct | 88 ms | 20040 KB | Output is correct |
13 | Correct | 140 ms | 19520 KB | Output is correct |
14 | Correct | 105 ms | 19764 KB | Output is correct |
15 | Correct | 91 ms | 19528 KB | Output is correct |
16 | Correct | 94 ms | 20044 KB | Output is correct |
17 | Correct | 85 ms | 19820 KB | Output is correct |
18 | Correct | 125 ms | 19936 KB | Output is correct |
19 | Correct | 8 ms | 11980 KB | Output is correct |
20 | Correct | 10 ms | 12060 KB | Output is correct |
21 | Correct | 8 ms | 11980 KB | Output is correct |
22 | Correct | 26 ms | 13728 KB | Output is correct |
23 | Correct | 119 ms | 20848 KB | Output is correct |
24 | Correct | 116 ms | 20548 KB | Output is correct |
25 | Correct | 134 ms | 20760 KB | Output is correct |
26 | Correct | 9 ms | 12056 KB | Output is correct |
27 | Correct | 102 ms | 20572 KB | Output is correct |
28 | Correct | 123 ms | 20164 KB | Output is correct |
29 | Correct | 126 ms | 20356 KB | Output is correct |
30 | Correct | 113 ms | 20164 KB | Output is correct |
31 | Correct | 131 ms | 20516 KB | Output is correct |
32 | Correct | 93 ms | 20440 KB | Output is correct |
33 | Correct | 99 ms | 20372 KB | Output is correct |
34 | Correct | 2614 ms | 65492 KB | Output is correct |
35 | Correct | 2976 ms | 61832 KB | Output is correct |
36 | Correct | 2942 ms | 61856 KB | Output is correct |
37 | Incorrect | 2103 ms | 66992 KB | Output isn't correct |
38 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 13136 KB | Output is correct |
2 | Correct | 97 ms | 20404 KB | Output is correct |
3 | Correct | 88 ms | 20024 KB | Output is correct |
4 | Correct | 118 ms | 20244 KB | Output is correct |
5 | Correct | 8 ms | 12108 KB | Output is correct |
6 | Correct | 82 ms | 20008 KB | Output is correct |
7 | Correct | 23 ms | 13244 KB | Output is correct |
8 | Correct | 102 ms | 20332 KB | Output is correct |
9 | Correct | 119 ms | 20036 KB | Output is correct |
10 | Correct | 122 ms | 20228 KB | Output is correct |
11 | Correct | 8 ms | 12080 KB | Output is correct |
12 | Correct | 88 ms | 20040 KB | Output is correct |
13 | Correct | 140 ms | 19520 KB | Output is correct |
14 | Correct | 105 ms | 19764 KB | Output is correct |
15 | Correct | 91 ms | 19528 KB | Output is correct |
16 | Correct | 94 ms | 20044 KB | Output is correct |
17 | Correct | 85 ms | 19820 KB | Output is correct |
18 | Correct | 125 ms | 19936 KB | Output is correct |
19 | Correct | 23 ms | 13268 KB | Output is correct |
20 | Correct | 92 ms | 20332 KB | Output is correct |
21 | Correct | 130 ms | 20000 KB | Output is correct |
22 | Correct | 158 ms | 20192 KB | Output is correct |
23 | Correct | 9 ms | 12108 KB | Output is correct |
24 | Correct | 121 ms | 19984 KB | Output is correct |
25 | Correct | 109 ms | 19580 KB | Output is correct |
26 | Correct | 108 ms | 19780 KB | Output is correct |
27 | Correct | 80 ms | 19548 KB | Output is correct |
28 | Correct | 131 ms | 20036 KB | Output is correct |
29 | Correct | 111 ms | 19904 KB | Output is correct |
30 | Correct | 110 ms | 19812 KB | Output is correct |
31 | Correct | 2148 ms | 64660 KB | Output is correct |
32 | Correct | 2208 ms | 68896 KB | Output is correct |
33 | Correct | 2076 ms | 65488 KB | Output is correct |
34 | Correct | 1475 ms | 68764 KB | Output is correct |
35 | Correct | 2258 ms | 60604 KB | Output is correct |
36 | Correct | 2299 ms | 101608 KB | Output is correct |
37 | Correct | 2709 ms | 107516 KB | Output is correct |
38 | Correct | 8 ms | 11980 KB | Output is correct |
39 | Correct | 10 ms | 12060 KB | Output is correct |
40 | Correct | 8 ms | 11980 KB | Output is correct |
41 | Correct | 26 ms | 13728 KB | Output is correct |
42 | Correct | 119 ms | 20848 KB | Output is correct |
43 | Correct | 116 ms | 20548 KB | Output is correct |
44 | Correct | 134 ms | 20760 KB | Output is correct |
45 | Correct | 9 ms | 12056 KB | Output is correct |
46 | Correct | 102 ms | 20572 KB | Output is correct |
47 | Correct | 123 ms | 20164 KB | Output is correct |
48 | Correct | 126 ms | 20356 KB | Output is correct |
49 | Correct | 113 ms | 20164 KB | Output is correct |
50 | Correct | 131 ms | 20516 KB | Output is correct |
51 | Correct | 93 ms | 20440 KB | Output is correct |
52 | Correct | 99 ms | 20372 KB | Output is correct |
53 | Correct | 2614 ms | 65492 KB | Output is correct |
54 | Correct | 2976 ms | 61832 KB | Output is correct |
55 | Correct | 2942 ms | 61856 KB | Output is correct |
56 | Incorrect | 2103 ms | 66992 KB | Output isn't correct |
57 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 13136 KB | Output is correct |
2 | Correct | 97 ms | 20404 KB | Output is correct |
3 | Correct | 88 ms | 20024 KB | Output is correct |
4 | Correct | 118 ms | 20244 KB | Output is correct |
5 | Correct | 8 ms | 12108 KB | Output is correct |
6 | Correct | 82 ms | 20008 KB | Output is correct |
7 | Correct | 23 ms | 13244 KB | Output is correct |
8 | Correct | 102 ms | 20332 KB | Output is correct |
9 | Correct | 119 ms | 20036 KB | Output is correct |
10 | Correct | 122 ms | 20228 KB | Output is correct |
11 | Correct | 8 ms | 12080 KB | Output is correct |
12 | Correct | 88 ms | 20040 KB | Output is correct |
13 | Correct | 140 ms | 19520 KB | Output is correct |
14 | Correct | 105 ms | 19764 KB | Output is correct |
15 | Correct | 91 ms | 19528 KB | Output is correct |
16 | Correct | 94 ms | 20044 KB | Output is correct |
17 | Correct | 85 ms | 19820 KB | Output is correct |
18 | Correct | 125 ms | 19936 KB | Output is correct |
19 | Correct | 23 ms | 13268 KB | Output is correct |
20 | Correct | 92 ms | 20332 KB | Output is correct |
21 | Correct | 130 ms | 20000 KB | Output is correct |
22 | Correct | 158 ms | 20192 KB | Output is correct |
23 | Correct | 9 ms | 12108 KB | Output is correct |
24 | Correct | 121 ms | 19984 KB | Output is correct |
25 | Correct | 109 ms | 19580 KB | Output is correct |
26 | Correct | 108 ms | 19780 KB | Output is correct |
27 | Correct | 80 ms | 19548 KB | Output is correct |
28 | Correct | 131 ms | 20036 KB | Output is correct |
29 | Correct | 111 ms | 19904 KB | Output is correct |
30 | Correct | 110 ms | 19812 KB | Output is correct |
31 | Correct | 2148 ms | 64660 KB | Output is correct |
32 | Correct | 2208 ms | 68896 KB | Output is correct |
33 | Correct | 2076 ms | 65488 KB | Output is correct |
34 | Correct | 1475 ms | 68764 KB | Output is correct |
35 | Correct | 2258 ms | 60604 KB | Output is correct |
36 | Correct | 2299 ms | 101608 KB | Output is correct |
37 | Correct | 2709 ms | 107516 KB | Output is correct |
38 | Correct | 24 ms | 13836 KB | Output is correct |
39 | Correct | 112 ms | 21480 KB | Output is correct |
40 | Correct | 109 ms | 21140 KB | Output is correct |
41 | Correct | 123 ms | 21316 KB | Output is correct |
42 | Correct | 8 ms | 12240 KB | Output is correct |
43 | Correct | 86 ms | 21152 KB | Output is correct |
44 | Correct | 152 ms | 20852 KB | Output is correct |
45 | Correct | 84 ms | 21124 KB | Output is correct |
46 | Correct | 77 ms | 20752 KB | Output is correct |
47 | Correct | 115 ms | 21208 KB | Output is correct |
48 | Correct | 115 ms | 21060 KB | Output is correct |
49 | Correct | 101 ms | 20952 KB | Output is correct |
50 | Correct | 2427 ms | 103308 KB | Output is correct |
51 | Correct | 2181 ms | 107316 KB | Output is correct |
52 | Correct | 2117 ms | 104120 KB | Output is correct |
53 | Correct | 1697 ms | 107448 KB | Output is correct |
54 | Correct | 2366 ms | 99580 KB | Output is correct |
55 | Correct | 2590 ms | 101524 KB | Output is correct |
56 | Correct | 2847 ms | 107320 KB | Output is correct |
57 | Correct | 3376 ms | 111608 KB | Output is correct |
58 | Correct | 3917 ms | 122404 KB | Output is correct |
59 | Correct | 3343 ms | 121044 KB | Output is correct |
60 | Correct | 1710 ms | 98712 KB | Output is correct |
61 | Execution timed out | 6058 ms | 144092 KB | Time limit exceeded |
62 | Halted | 0 ms | 0 KB | - |