Submission #971267

# Submission time Handle Problem Language Result Execution time Memory
971267 2024-04-28T09:23:08 Z kl0989e From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
4606 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define pi pair<int, int>
#define all(x) (x).begin(),(x).end()

const int maxn=250000+10;
vector<vi> graph(maxn);
vector<pi> has_w(maxn,{-1,-1});

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    int a,b;
    for (int i=0; i<m; i++) {
        cin >> a >> b;
        graph[--a].pb(--b);
        graph[b].pb(a);
    }
    int k;
    cin >> k;
    vi empt;
    for (int i=0; i<k; i++) {
        cin >> a;
        for (int j=0; j<a; j++) {
            cin >> b;
            has_w[--b]={a,j};
        }
    }
    priority_queue<pi,vector<pi>,greater<pi>> q;
    q.emplace(0,0);
    vi mintime(n,1e9);
    mintime[0]=0;
    while (q.size()) {
        auto [time,cur]=q.top();
        q.pop();
        if (cur==n-1) {
            cout << time << '\n';
            return 0;
        }
        if (has_w[cur].fi==-1 && mintime[cur]!=time) {
            continue;
        }
        if (has_w[cur].fi!=-1 && mintime[cur]+has_w[cur].fi<time) {
            continue;
        }
        for (int to:graph[cur]) {
            if (has_w[to].fi==-1) {
                if (mintime[to]>1+time) {
                    mintime[to]=1+time;
                    q.emplace(1+time,to);
                }
            }
            else if (has_w[cur].fi!=-1) {
                if (time%has_w[to].fi==has_w[to].se && (time+1)%has_w[cur].fi==has_w[cur].se) {
                    continue;
                }
                if ((time+1)%has_w[to].fi==has_w[to].se) {
                    continue;
                }
                if (mintime[to]+has_w[to].fi>1+time) {
                    mintime[to]=min(1+time,mintime[to]);
                    q.emplace(1+time,to);
                }
            }
            else {
                if ((time+1)%has_w[to].fi!=has_w[to].se) {
                    if (mintime[to]+has_w[to].fi>1+time) {
                        mintime[to]=min(1+time,mintime[to]);
                        q.emplace(1+time,to);
                    }
                }
                int t=((1ll*time-has_w[to].se+has_w[to].fi)/has_w[to].fi)*has_w[to].fi+1+has_w[to].se;
                if (mintime[to]+has_w[to].fi>t) {
                    mintime[to]=min(t,mintime[to]);
                    q.emplace(t,to);
                }
            }
        }
    }
    cout << "impossible\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 10716 KB Output is correct
2 Runtime error 4606 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 10712 KB Output is correct
2 Runtime error 4559 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 10712 KB Output is correct
2 Runtime error 4559 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 10712 KB Output is correct
2 Runtime error 4559 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 10716 KB Output is correct
2 Runtime error 4606 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 10716 KB Output is correct
2 Runtime error 4606 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 10716 KB Output is correct
2 Runtime error 4606 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -