Submission #846839

#TimeUsernameProblemLanguageResultExecution timeMemory
846839MinaRagy06From Hacks to Snitches (BOI21_watchmen)C++17
5 / 100
787 ms66392 KiB
#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(); //cout << node << ' ' << cur << ' ' << a[0][cur] << ' ' << cost << '\n'; 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 == a[0][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 (stderr)

watchmen.cpp: In function 'int main()':
watchmen.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for (int i = 0; i < a[0].size(); i++) {
      |                     ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...