Submission #427678

# Submission time Handle Problem Language Result Execution time Memory
427678 2021-06-14T18:41:58 Z duality From Hacks to Snitches (BOI21_watchmen) C++11
35 / 100
3750 ms 197492 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;

vi adjList[250000];
pair<int,pii> p[250000];
bool comp(int a,int b) {
    return p[a] < p[b];
}
int pos[250000];
vector<LLI> dist[250000];
priority_queue<pair<LLI,int> > H;
int relax(int u,LLI d) {
    if ((dist[u][d % p[u].first] == -1) || (d < dist[u][d % p[u].first])) {
        dist[u][d % p[u].first] = d;
        H.push(mp(-d,u));
    }
    return 0;
}
int done[250000],done2[250000];
set<pii> done3[250000];
int main() {
    int i,j;
    int N,M,K;
    int u,v,l;
    scanf("%d %d",&N,&M);
    for (i = 0; i < M; i++) {
        scanf("%d %d",&u,&v);
        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);
    }
    for (i = 0; i < N; i++) {
        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;
        LLI d = -H.top().first;
        H.pop();

        if (d > dist[u][d % p[u].first]) continue;
        else if (u == N-1) {
            printf("%lld\n",d);
            return 0;
        }
        if ((p[u].first == 1) || (((d+1) % p[u].first) != p[u].second.first)) relax(u,d+1);
        if (done[u] && (dist[u][(d+p[u].first-1) % p[u].first] == d-1)) continue;
        for (i = done[u] ? pos[u]:0; i < adjList[u].size(); i++) {
            int v = adjList[u][i];
            if (p[v].first == 1) relax(v,d+1);
            else if (p[u].first == 1) {
                if (done2[v]) continue;
                else {
                    for (j = 0; j < p[v].first; j++) {
                        LLI d2 = d+j+1;
                        if ((d2 % p[v].first) != p[v].second.first) relax(v,d2);
                    }
                    done2[v] = 1;
                }
            }
            else if (p[u].second.second == p[v].second.second) {
                if (((d+1) % p[v].first) == p[v].second.first) continue;
                if (((d % p[v].first) == p[v].second.first) && (((d+1) % p[u].first) == p[u].second.first)) continue;
                relax(v,d+1);
            }
            else {
                if (done3[v].count(mp(d % p[v].first,p[u].first))) continue;
                vector<LLI> dd(p[v].first,-1);
                priority_queue<LLI> H2;
                for (j = 0; j < ((((p[u].second.first-d) % p[u].first)+p[u].first) % p[u].first); j++) {
                    dd[(d+j) % p[v].first] = d+j;
                    if (j == p[v].first) break;
                }
                for (j = 0; j < p[v].first; j++) {
                    if (dd[j] != -1) H2.push(-dd[j]);
                }
                while (!H2.empty()) {
                    LLI d = -H2.top();
                    H2.pop();

                    if (d > dd[d % p[v].first]) continue;
                    if ((dd[(d+p[u].first) % p[v].first] == -1) || (d+p[u].first < dd[(d+p[u].first) % p[v].first])) {
                        dd[(d+p[u].first) % p[v].first] = d+p[u].first;
                        H2.push(-(d+p[u].first));
                    }
                }
                for (j = 0; j < p[v].first; j++) {
                    if (dd[j] != -1) {
                        LLI d2 = dd[j]+1;
                        if ((d2 % p[v].first) != p[v].second.first) relax(v,d2);
                    }
                }
                done3[v].insert(mp(d % p[v].first,p[u].first));
            }
        }
        done[u] = 1;
    }
    printf("impossible\n");

    return 0;
}

Compilation message

watchmen.cpp: In function 'int main()':
watchmen.cpp:51:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         while ((pos[i] < adjList[i].size()) && (p[adjList[i][pos[i]]].first == 1)) pos[i]++;
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~
watchmen.cpp:66:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (i = done[u] ? pos[u]:0; i < adjList[u].size(); i++) {
      |                                      ~~^~~~~~~~~~~~~~~~~~~
watchmen.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
watchmen.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%d %d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~~
watchmen.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%d",&K);
      |     ~~~~~^~~~~~~~~
watchmen.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         scanf("%d",&l);
      |         ~~~~~^~~~~~~~~
watchmen.cpp:41:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         for (j = 0; j < l; j++) scanf("%d",&v),p[v-1] = mp(l,mp(j,i));
      |                                 ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 44 ms 25788 KB Output is correct
2 Correct 135 ms 33220 KB Output is correct
3 Correct 140 ms 33004 KB Output is correct
4 Correct 136 ms 33428 KB Output is correct
5 Correct 16 ms 23884 KB Output is correct
6 Correct 139 ms 33064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 25680 KB Output is correct
2 Correct 127 ms 33264 KB Output is correct
3 Correct 136 ms 33160 KB Output is correct
4 Correct 138 ms 33352 KB Output is correct
5 Correct 16 ms 23924 KB Output is correct
6 Correct 121 ms 33088 KB Output is correct
7 Correct 116 ms 32536 KB Output is correct
8 Correct 113 ms 32852 KB Output is correct
9 Correct 127 ms 32548 KB Output is correct
10 Correct 141 ms 33064 KB Output is correct
11 Correct 113 ms 32896 KB Output is correct
12 Correct 113 ms 32836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 25680 KB Output is correct
2 Correct 127 ms 33264 KB Output is correct
3 Correct 136 ms 33160 KB Output is correct
4 Correct 138 ms 33352 KB Output is correct
5 Correct 16 ms 23924 KB Output is correct
6 Correct 121 ms 33088 KB Output is correct
7 Correct 116 ms 32536 KB Output is correct
8 Correct 113 ms 32852 KB Output is correct
9 Correct 127 ms 32548 KB Output is correct
10 Correct 141 ms 33064 KB Output is correct
11 Correct 113 ms 32896 KB Output is correct
12 Correct 113 ms 32836 KB Output is correct
13 Correct 43 ms 25676 KB Output is correct
14 Correct 127 ms 33252 KB Output is correct
15 Correct 116 ms 33096 KB Output is correct
16 Correct 131 ms 33436 KB Output is correct
17 Correct 17 ms 23884 KB Output is correct
18 Correct 116 ms 33092 KB Output is correct
19 Correct 141 ms 32652 KB Output is correct
20 Correct 120 ms 32940 KB Output is correct
21 Correct 112 ms 32500 KB Output is correct
22 Correct 156 ms 33068 KB Output is correct
23 Correct 137 ms 32912 KB Output is correct
24 Correct 118 ms 32808 KB Output is correct
25 Correct 3020 ms 115524 KB Output is correct
26 Correct 2734 ms 119992 KB Output is correct
27 Correct 2519 ms 116716 KB Output is correct
28 Correct 2008 ms 119392 KB Output is correct
29 Correct 2795 ms 113248 KB Output is correct
30 Correct 2702 ms 115672 KB Output is correct
31 Correct 2985 ms 120568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 25680 KB Output is correct
2 Correct 127 ms 33264 KB Output is correct
3 Correct 136 ms 33160 KB Output is correct
4 Correct 138 ms 33352 KB Output is correct
5 Correct 16 ms 23924 KB Output is correct
6 Correct 121 ms 33088 KB Output is correct
7 Correct 116 ms 32536 KB Output is correct
8 Correct 113 ms 32852 KB Output is correct
9 Correct 127 ms 32548 KB Output is correct
10 Correct 141 ms 33064 KB Output is correct
11 Correct 113 ms 32896 KB Output is correct
12 Correct 113 ms 32836 KB Output is correct
13 Correct 43 ms 25676 KB Output is correct
14 Correct 127 ms 33252 KB Output is correct
15 Correct 116 ms 33096 KB Output is correct
16 Correct 131 ms 33436 KB Output is correct
17 Correct 17 ms 23884 KB Output is correct
18 Correct 116 ms 33092 KB Output is correct
19 Correct 141 ms 32652 KB Output is correct
20 Correct 120 ms 32940 KB Output is correct
21 Correct 112 ms 32500 KB Output is correct
22 Correct 156 ms 33068 KB Output is correct
23 Correct 137 ms 32912 KB Output is correct
24 Correct 118 ms 32808 KB Output is correct
25 Correct 3020 ms 115524 KB Output is correct
26 Correct 2734 ms 119992 KB Output is correct
27 Correct 2519 ms 116716 KB Output is correct
28 Correct 2008 ms 119392 KB Output is correct
29 Correct 2795 ms 113248 KB Output is correct
30 Correct 2702 ms 115672 KB Output is correct
31 Correct 2985 ms 120568 KB Output is correct
32 Correct 42 ms 25744 KB Output is correct
33 Correct 121 ms 33264 KB Output is correct
34 Correct 144 ms 33116 KB Output is correct
35 Correct 128 ms 33332 KB Output is correct
36 Correct 16 ms 23844 KB Output is correct
37 Correct 125 ms 33092 KB Output is correct
38 Correct 123 ms 32568 KB Output is correct
39 Correct 129 ms 32772 KB Output is correct
40 Correct 109 ms 32580 KB Output is correct
41 Correct 120 ms 33096 KB Output is correct
42 Correct 130 ms 32916 KB Output is correct
43 Correct 116 ms 32836 KB Output is correct
44 Correct 2927 ms 115712 KB Output is correct
45 Correct 2786 ms 119848 KB Output is correct
46 Correct 2690 ms 116600 KB Output is correct
47 Correct 2224 ms 119328 KB Output is correct
48 Correct 2770 ms 113056 KB Output is correct
49 Correct 2692 ms 115516 KB Output is correct
50 Correct 3028 ms 120388 KB Output is correct
51 Correct 3394 ms 132652 KB Output is correct
52 Correct 3498 ms 149244 KB Output is correct
53 Correct 3394 ms 150852 KB Output is correct
54 Correct 1937 ms 111560 KB Output is correct
55 Correct 3750 ms 197492 KB Output is correct
56 Correct 3462 ms 155088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 25788 KB Output is correct
2 Correct 135 ms 33220 KB Output is correct
3 Correct 140 ms 33004 KB Output is correct
4 Correct 136 ms 33428 KB Output is correct
5 Correct 16 ms 23884 KB Output is correct
6 Correct 139 ms 33064 KB Output is correct
7 Correct 42 ms 25680 KB Output is correct
8 Correct 127 ms 33264 KB Output is correct
9 Correct 136 ms 33160 KB Output is correct
10 Correct 138 ms 33352 KB Output is correct
11 Correct 16 ms 23924 KB Output is correct
12 Correct 121 ms 33088 KB Output is correct
13 Correct 116 ms 32536 KB Output is correct
14 Correct 113 ms 32852 KB Output is correct
15 Correct 127 ms 32548 KB Output is correct
16 Correct 141 ms 33064 KB Output is correct
17 Correct 113 ms 32896 KB Output is correct
18 Correct 113 ms 32836 KB Output is correct
19 Correct 14 ms 23796 KB Output is correct
20 Correct 15 ms 23804 KB Output is correct
21 Correct 15 ms 23800 KB Output is correct
22 Correct 44 ms 25796 KB Output is correct
23 Correct 136 ms 33292 KB Output is correct
24 Correct 126 ms 33152 KB Output is correct
25 Correct 120 ms 33352 KB Output is correct
26 Correct 15 ms 23884 KB Output is correct
27 Correct 121 ms 32992 KB Output is correct
28 Correct 113 ms 32612 KB Output is correct
29 Correct 110 ms 32828 KB Output is correct
30 Correct 121 ms 32600 KB Output is correct
31 Correct 137 ms 33052 KB Output is correct
32 Correct 125 ms 32836 KB Output is correct
33 Correct 129 ms 32804 KB Output is correct
34 Correct 3006 ms 116536 KB Output is correct
35 Correct 2837 ms 112960 KB Output is correct
36 Correct 2819 ms 113040 KB Output is correct
37 Incorrect 2573 ms 117504 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 25788 KB Output is correct
2 Correct 135 ms 33220 KB Output is correct
3 Correct 140 ms 33004 KB Output is correct
4 Correct 136 ms 33428 KB Output is correct
5 Correct 16 ms 23884 KB Output is correct
6 Correct 139 ms 33064 KB Output is correct
7 Correct 42 ms 25680 KB Output is correct
8 Correct 127 ms 33264 KB Output is correct
9 Correct 136 ms 33160 KB Output is correct
10 Correct 138 ms 33352 KB Output is correct
11 Correct 16 ms 23924 KB Output is correct
12 Correct 121 ms 33088 KB Output is correct
13 Correct 116 ms 32536 KB Output is correct
14 Correct 113 ms 32852 KB Output is correct
15 Correct 127 ms 32548 KB Output is correct
16 Correct 141 ms 33064 KB Output is correct
17 Correct 113 ms 32896 KB Output is correct
18 Correct 113 ms 32836 KB Output is correct
19 Correct 43 ms 25676 KB Output is correct
20 Correct 127 ms 33252 KB Output is correct
21 Correct 116 ms 33096 KB Output is correct
22 Correct 131 ms 33436 KB Output is correct
23 Correct 17 ms 23884 KB Output is correct
24 Correct 116 ms 33092 KB Output is correct
25 Correct 141 ms 32652 KB Output is correct
26 Correct 120 ms 32940 KB Output is correct
27 Correct 112 ms 32500 KB Output is correct
28 Correct 156 ms 33068 KB Output is correct
29 Correct 137 ms 32912 KB Output is correct
30 Correct 118 ms 32808 KB Output is correct
31 Correct 3020 ms 115524 KB Output is correct
32 Correct 2734 ms 119992 KB Output is correct
33 Correct 2519 ms 116716 KB Output is correct
34 Correct 2008 ms 119392 KB Output is correct
35 Correct 2795 ms 113248 KB Output is correct
36 Correct 2702 ms 115672 KB Output is correct
37 Correct 2985 ms 120568 KB Output is correct
38 Correct 14 ms 23796 KB Output is correct
39 Correct 15 ms 23804 KB Output is correct
40 Correct 15 ms 23800 KB Output is correct
41 Correct 44 ms 25796 KB Output is correct
42 Correct 136 ms 33292 KB Output is correct
43 Correct 126 ms 33152 KB Output is correct
44 Correct 120 ms 33352 KB Output is correct
45 Correct 15 ms 23884 KB Output is correct
46 Correct 121 ms 32992 KB Output is correct
47 Correct 113 ms 32612 KB Output is correct
48 Correct 110 ms 32828 KB Output is correct
49 Correct 121 ms 32600 KB Output is correct
50 Correct 137 ms 33052 KB Output is correct
51 Correct 125 ms 32836 KB Output is correct
52 Correct 129 ms 32804 KB Output is correct
53 Correct 3006 ms 116536 KB Output is correct
54 Correct 2837 ms 112960 KB Output is correct
55 Correct 2819 ms 113040 KB Output is correct
56 Incorrect 2573 ms 117504 KB Output isn't correct
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 25788 KB Output is correct
2 Correct 135 ms 33220 KB Output is correct
3 Correct 140 ms 33004 KB Output is correct
4 Correct 136 ms 33428 KB Output is correct
5 Correct 16 ms 23884 KB Output is correct
6 Correct 139 ms 33064 KB Output is correct
7 Correct 42 ms 25680 KB Output is correct
8 Correct 127 ms 33264 KB Output is correct
9 Correct 136 ms 33160 KB Output is correct
10 Correct 138 ms 33352 KB Output is correct
11 Correct 16 ms 23924 KB Output is correct
12 Correct 121 ms 33088 KB Output is correct
13 Correct 116 ms 32536 KB Output is correct
14 Correct 113 ms 32852 KB Output is correct
15 Correct 127 ms 32548 KB Output is correct
16 Correct 141 ms 33064 KB Output is correct
17 Correct 113 ms 32896 KB Output is correct
18 Correct 113 ms 32836 KB Output is correct
19 Correct 43 ms 25676 KB Output is correct
20 Correct 127 ms 33252 KB Output is correct
21 Correct 116 ms 33096 KB Output is correct
22 Correct 131 ms 33436 KB Output is correct
23 Correct 17 ms 23884 KB Output is correct
24 Correct 116 ms 33092 KB Output is correct
25 Correct 141 ms 32652 KB Output is correct
26 Correct 120 ms 32940 KB Output is correct
27 Correct 112 ms 32500 KB Output is correct
28 Correct 156 ms 33068 KB Output is correct
29 Correct 137 ms 32912 KB Output is correct
30 Correct 118 ms 32808 KB Output is correct
31 Correct 3020 ms 115524 KB Output is correct
32 Correct 2734 ms 119992 KB Output is correct
33 Correct 2519 ms 116716 KB Output is correct
34 Correct 2008 ms 119392 KB Output is correct
35 Correct 2795 ms 113248 KB Output is correct
36 Correct 2702 ms 115672 KB Output is correct
37 Correct 2985 ms 120568 KB Output is correct
38 Correct 42 ms 25744 KB Output is correct
39 Correct 121 ms 33264 KB Output is correct
40 Correct 144 ms 33116 KB Output is correct
41 Correct 128 ms 33332 KB Output is correct
42 Correct 16 ms 23844 KB Output is correct
43 Correct 125 ms 33092 KB Output is correct
44 Correct 123 ms 32568 KB Output is correct
45 Correct 129 ms 32772 KB Output is correct
46 Correct 109 ms 32580 KB Output is correct
47 Correct 120 ms 33096 KB Output is correct
48 Correct 130 ms 32916 KB Output is correct
49 Correct 116 ms 32836 KB Output is correct
50 Correct 2927 ms 115712 KB Output is correct
51 Correct 2786 ms 119848 KB Output is correct
52 Correct 2690 ms 116600 KB Output is correct
53 Correct 2224 ms 119328 KB Output is correct
54 Correct 2770 ms 113056 KB Output is correct
55 Correct 2692 ms 115516 KB Output is correct
56 Correct 3028 ms 120388 KB Output is correct
57 Correct 3394 ms 132652 KB Output is correct
58 Correct 3498 ms 149244 KB Output is correct
59 Correct 3394 ms 150852 KB Output is correct
60 Correct 1937 ms 111560 KB Output is correct
61 Correct 3750 ms 197492 KB Output is correct
62 Correct 3462 ms 155088 KB Output is correct
63 Correct 14 ms 23796 KB Output is correct
64 Correct 15 ms 23804 KB Output is correct
65 Correct 15 ms 23800 KB Output is correct
66 Correct 44 ms 25796 KB Output is correct
67 Correct 136 ms 33292 KB Output is correct
68 Correct 126 ms 33152 KB Output is correct
69 Correct 120 ms 33352 KB Output is correct
70 Correct 15 ms 23884 KB Output is correct
71 Correct 121 ms 32992 KB Output is correct
72 Correct 113 ms 32612 KB Output is correct
73 Correct 110 ms 32828 KB Output is correct
74 Correct 121 ms 32600 KB Output is correct
75 Correct 137 ms 33052 KB Output is correct
76 Correct 125 ms 32836 KB Output is correct
77 Correct 129 ms 32804 KB Output is correct
78 Correct 3006 ms 116536 KB Output is correct
79 Correct 2837 ms 112960 KB Output is correct
80 Correct 2819 ms 113040 KB Output is correct
81 Incorrect 2573 ms 117504 KB Output isn't correct
82 Halted 0 ms 0 KB -