Submission #845191

#TimeUsernameProblemLanguageResultExecution timeMemory
845191vjudge1Birmingham (COCI20_birmingham)C++17
70 / 70
140 ms10024 KiB
#include <bits/stdc++.h> using namespace std; int main() { int N, M, Q, K; cin >> N >> M >> Q >> K; vector<int> s(Q); for (int i = 0;i < Q; ++i) { cin >> s[i]; s[i] -= 1; } vector<vector<int>> g(N); for (int i = 0;i < M; ++i) { int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); } queue<array<int, 2>> q; for (int i = 0;i < Q; ++i) { q.push({0, s[i]}); } vector<int> dist(N, -1); while (q.size()) { auto [d, u] = q.front(); q.pop(); if (dist[u] != -1) { continue; } dist[u] = d; for (int v : g[u]) { q.push({d+1, v}); } } vector<int> idx(N), ans(N); iota(idx.begin(), idx.end(), 0); sort(idx.begin(), idx.end(), [&](int i, int j) { return dist[i] < dist[j]; }); int64_t day = 0, can = 0; for (int i = 0;i < N; ++i) { int j = idx[i]; while (can < dist[j]) { day += 1; can += K * day; } ans[j] = day; } for (int i = 0;i < N; ++i) { cout << ans[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...
#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...