답안 #527690

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527690 2022-02-18T03:22:38 Z 79brue From Hacks to Snitches (BOI21_watchmen) C++14
0 / 100
111 ms 34520 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];
queue<dat> pq[1602];
int cnt[250002];

void update(dat tmp){
    if(visited[tmp.x][tmp.f] || cnt[tmp.x] >= 5) return;
    visited[tmp.x][tmp.f] = 1;
    dist[tmp.x][tmp.f] = tmp.y;
    pq[tmp.y%1600].push(tmp);
    cnt[tmp.x]++;
}

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));
    for(int td=0; ; td++){
        bool exist = 0;
        for(int d=td*1600; d<td*1600+1600; d++){
            while(!pq[d%1600].empty()){
                exist = 1;
                dat tmp = pq[d%1600].front(); pq[d%1600].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(cycleIdx[nxt] != (y+1)%cycleLen[nxt]) update(dat(nxt, (y+1)%cycleLen[nxt], y+1));
                            int tn = (y+1-cycleIdx[nxt]-1+cycleLen[nxt]-1) / cycleLen[nxt] * cycleLen[nxt] + cycleIdx[nxt]+1;
                            update(dat(nxt, tn%cycleLen[nxt], tn));
                        }
                    }
                }
                else{
                    for(int nxt: link[x]){
                        if(cycleLen[nxt] == 1) update(dat(nxt, 0, y+1));
                        else{
                            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));
                        }
                    }
                }
            }
        }
        if(!exist) break;
    }

    printf("impossible");
}

Compilation message

watchmen.cpp: In function 'int main()':
watchmen.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
watchmen.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
watchmen.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d", &k);
      |     ~~~~~^~~~~~~~~~
watchmen.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf("%d", &l);
      |         ~~~~~^~~~~~~~~~
watchmen.cpp:49:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |             scanf("%d", &tmp);
      |             ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 24388 KB Output is correct
2 Incorrect 97 ms 34488 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 24396 KB Output is correct
2 Incorrect 111 ms 34520 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 24396 KB Output is correct
2 Incorrect 111 ms 34520 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 24396 KB Output is correct
2 Incorrect 111 ms 34520 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 24388 KB Output is correct
2 Incorrect 97 ms 34488 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 24388 KB Output is correct
2 Incorrect 97 ms 34488 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 24388 KB Output is correct
2 Incorrect 97 ms 34488 KB Output isn't correct
3 Halted 0 ms 0 KB -