답안 #846837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
846837 2023-09-08T13:58:49 Z MinaRagy06 From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
21 ms 62300 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);
    priority_queue<array<int, 3>> q;
    q.push({1, 0, 0});
    dist[1][0] = 0;
    while (q.size()) {
        int node = q.top()[1];
        int cur = q.top()[2];
        int cost = -q.top()[0];
        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({-(cost + 1), node, newcur});
        }
        for (auto nxt : adj[node]) {
            if (nxt == a[0][cur] && node == a[0][newcur]) continue;
            if (node == a[0][newcur]) continue;
            if (cost + 1 < dist[nxt][newcur]) {
                dist[nxt][newcur] = cost + 1;
                q.push({-(cost + 1), nxt, newcur});
            }
        }
    }
    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++) {
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 62300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 62300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 62300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 62300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 62300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 62300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 62300 KB Output isn't correct
2 Halted 0 ms 0 KB -