Submission #238460

#TimeUsernameProblemLanguageResultExecution timeMemory
238460dimitar_neBirmingham (COCI20_birmingham)C++14
70 / 70
157 ms7928 KiB
#include <bits/stdc++.h> #define endl '\n' #define MAXN 100003 using namespace std; int n, m, t, k; vector <int> adj[MAXN]; int dist[MAXN]; queue <int> q; void input() { cin >> n >> m >> t >> k; for (int i = 0; i <= n; ++i) dist[i] = -1; for (int i = 0; i < t; ++i) { int x; cin >> x; dist[x] = 0; q.push(x); } for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } } void bfs() { while (!q.empty()) { int tmp = q.front(); q.pop(); for (auto nb: adj[tmp]) { if (dist[nb] == -1 || dist[nb] > dist[tmp] + 1) { dist[nb] = dist[tmp] + 1; q.push(nb); } } } } int get_ans(int x) { if (x == 0) return 0; if (x <= k) return 1; int d = k; for (int i = 2; ; ++i) { d += i * k; if (d >= x) return i; } } void solve() { bfs(); cout << get_ans(dist[1]); for (int i = 2; i <= n; ++i) { cout << " " << get_ans(dist[i]);// << dist[i] << endl; } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); input(); solve(); return 0; }
#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...