Submission #527343

# Submission time Handle Problem Language Result Execution time Memory
527343 2022-02-17T09:13:51 Z 79brue From Hacks to Snitches (BOI21_watchmen) C++14
0 / 100
119 ms 32580 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct dat{
    int x, f, y;
    dat(){}
    dat(int x, int f, int y): x(x), f(f), y(y){}

    bool operator<(const dat &r)const{
        return y>r.y;
    }
};

int n, m, k;
vector<int> link[250002];
int cycleLen[250002];
int cycleIdx[250002];
vector<int> dist[250002];
vector<bool> visited[250002];
priority_queue<dat> pq;

void update(dat tmp){
    if(visited[tmp.x][tmp.f]) return;
    visited[tmp.x][tmp.f] = 1;
    dist[tmp.x][tmp.f] = tmp.y;
    pq.push(tmp);
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=m; i++){
        int x, y;
        scanf("%d %d", &x, &y);
        link[x].push_back(y);
        link[y].push_back(x);
    }

    scanf("%d", &k);
    while(k--){
        int l;
        scanf("%d", &l);
        for(int j=0; j<l; j++){
            int tmp;
            scanf("%d", &tmp);
            cycleLen[tmp] = l;
            cycleIdx[tmp] = j;
        }
    }

    for(int i=1; i<=n; i++){
        if(!cycleLen[i]) cycleLen[i] = 1;
        dist[i] = vector<int> (cycleLen[i], 1e9);
        visited[i].resize(cycleLen[i]);
    }

    update(dat(1, 0, 0));
    while(!pq.empty()){
        dat tmp = pq.top(); pq.pop();
        int x = tmp.x, f = tmp.f, y = tmp.y;
        assert(f < cycleLen[x]);

        if(x==n){
            printf("%d", y);
            return 0;
        }

        if(cycleLen[x] == 1){
            for(int nxt: link[x]){
                if(cycleLen[nxt] == 1) update(dat(nxt, 0, y+1));
                else{
                    if(visited[nxt][0] || visited[nxt][1] || visited[nxt][2]) continue;
                    for(int j=0; j<cycleLen[nxt]; j++){
                        int nf = (y+1+j)%cycleLen[nxt];
                        if(nf == cycleIdx[nxt]) continue;
                        update(dat(nxt, nf, y+j+1));
                    }
                }
            }
        }
        else{
            for(int nxt: link[x]){
                if(cycleLen[nxt] == 1) update(dat(nxt, 0, y+1));
                else{
                    if(visited[nxt][0] || visited[nxt][1] || visited[nxt][2]) continue;
                    int nf = (f+1)%cycleLen[nxt];
                    if(nf == cycleIdx[nxt]) continue;
                    if(nf == cycleIdx[x] && f%cycleLen[nxt] == cycleIdx[nxt]) continue;
                    update(dat(nxt, nf, y+1));
                }
            }
        }
    }

    printf("impossible");
}

Compilation message

watchmen.cpp: In function 'int main()':
watchmen.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
watchmen.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
watchmen.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d", &k);
      |     ~~~~~^~~~~~~~~~
watchmen.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         scanf("%d", &l);
      |         ~~~~~^~~~~~~~~~
watchmen.cpp:47:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |             scanf("%d", &tmp);
      |             ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 23644 KB Output is correct
2 Correct 91 ms 32432 KB Output is correct
3 Correct 101 ms 31884 KB Output is correct
4 Correct 111 ms 32236 KB Output is correct
5 Incorrect 11 ms 21832 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 23640 KB Output is correct
2 Correct 97 ms 32580 KB Output is correct
3 Correct 105 ms 31860 KB Output is correct
4 Correct 119 ms 32172 KB Output is correct
5 Incorrect 12 ms 21800 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 23640 KB Output is correct
2 Correct 97 ms 32580 KB Output is correct
3 Correct 105 ms 31860 KB Output is correct
4 Correct 119 ms 32172 KB Output is correct
5 Incorrect 12 ms 21800 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 23640 KB Output is correct
2 Correct 97 ms 32580 KB Output is correct
3 Correct 105 ms 31860 KB Output is correct
4 Correct 119 ms 32172 KB Output is correct
5 Incorrect 12 ms 21800 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 23644 KB Output is correct
2 Correct 91 ms 32432 KB Output is correct
3 Correct 101 ms 31884 KB Output is correct
4 Correct 111 ms 32236 KB Output is correct
5 Incorrect 11 ms 21832 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 23644 KB Output is correct
2 Correct 91 ms 32432 KB Output is correct
3 Correct 101 ms 31884 KB Output is correct
4 Correct 111 ms 32236 KB Output is correct
5 Incorrect 11 ms 21832 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 23644 KB Output is correct
2 Correct 91 ms 32432 KB Output is correct
3 Correct 101 ms 31884 KB Output is correct
4 Correct 111 ms 32236 KB Output is correct
5 Incorrect 11 ms 21832 KB Output isn't correct
6 Halted 0 ms 0 KB -