Submission #845246

#TimeUsernameProblemLanguageResultExecution timeMemory
845246vjudge1Birmingham (COCI20_birmingham)C++17
70 / 70
122 ms8904 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; constexpr static int MXN = 1e5; int n, m, k, q; bitset<MXN> visited; vector<int> g[MXN]; vector<int> v; int vv[MXN]; int res[MXN]; int main() { cin >> n >> m >> q >> k; for (int i = 0; i < q; i++) { int val; cin >> val; v.pb(val-1); } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--,b--; g[a].pb(b); g[b].pb(a); } for (int i : v) visited[i] = true; int j = 1; while (!v.empty()) { queue<array<int, 2>> t; for (int i : v) t.push({i, j*k}); v.clear(); while (t.size()) { auto [node, s] = t.front(); t.pop(); if (s != j*k) res[node] = j; if (s == 0) { v.pb(node); continue; } for (int c : g[node]) { if (!visited[c]) { t.push({c, s-1}); visited[c] = true; } } } j++; } for (int i = 0; i < n; i++) cout << res[i] << " "; cout << "\n"; }
#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...
#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...