Submission #846818

# Submission time Handle Problem Language Result Execution time Memory
846818 2023-09-08T13:39:55 Z MinaRagy06 From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
339 ms 65788 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

const int N = 100'005;
vector<int> adj[N];
int dist[N][150];
vector<int> a[150];
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0, u, v; i < m; i++) {
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
        int l;
        cin >> l;
        a[i].resize(l);
        for (int j = 0; j < l; j++) {
            cin >> a[i][j];
        }
    }
    memset(dist, '?', sizeof dist);
    queue<array<int, 3>> q;
    q.push({1, 0, 0});
    dist[1][0] = 0;
    while (q.size()) {
        int node = q.front()[0];
        int cur = q.front()[1];
        int cost = q.front()[2];
        q.pop();
        int newcur = (cur + 1) % a[0].size();
        if (a[0][newcur] != node && cost + 1 < dist[node][newcur]) {
            dist[node][newcur] = cost + 1;
            q.push({node, newcur, cost + 1});
        }
        for (auto nxt : adj[node]) {
            if (nxt == a[0][cur] && node == newcur) continue;
            if (nxt == a[0][newcur]) continue;
            if (cost + 1 < dist[nxt][newcur]) {
                dist[nxt][newcur] = cost + 1;
                q.push({nxt, newcur, cost + 1});
            }
        }
    }
    int mn = 1e9;
    for (int i = 0; i < a[0].size(); i++) {
        mn = min(mn, dist[n][i]);
    }
    if (mn == int(1e9)) {
        cout << "impossible\n";
    } else {
        cout << mn << '\n';
    }
    return 0;
}

Compilation message

watchmen.cpp: In function 'int main()':
watchmen.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (int i = 0; i < a[0].size(); i++) {
      |                     ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 51 ms 62808 KB Output is correct
2 Incorrect 339 ms 65788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 62980 KB Output is correct
2 Incorrect 327 ms 65784 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 62980 KB Output is correct
2 Incorrect 327 ms 65784 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 62980 KB Output is correct
2 Incorrect 327 ms 65784 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 62808 KB Output is correct
2 Incorrect 339 ms 65788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 62808 KB Output is correct
2 Incorrect 339 ms 65788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 62808 KB Output is correct
2 Incorrect 339 ms 65788 KB Output isn't correct
3 Halted 0 ms 0 KB -