Submission #238555

#TimeUsernameProblemLanguageResultExecution timeMemory
238555BorbiBirmingham (COCI20_birmingham)C++14
70 / 70
119 ms8312 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int n, m, f, k; vector <int> graph[MAXN]; queue <int> q; int vis[MAXN]; int lvl[MAXN]; void read_input() { cin >> n >> m >> f >> k; for(int i = 1; i <= n; i++) { vis[i] = -1; lvl[i] = -1; } int h; for(int i = 0; i < f; i++) { cin >> h; q.push(h); lvl[h] = 0; vis[h] = 0; } int v, w; for(int i = 0; i < m; i++) { cin >> v >> w; graph[v].push_back(w); graph[w].push_back(v); } } void solve() { while(!q.empty()) { int v = q.front(); q.pop(); //cout << v << "\n"; int new_l = lvl[v]; int ost = vis[v] - 1; if(ost < 0) { new_l++; ost = k * new_l; ost--; //cout << " " << v << " " << vis[v] << " " << new_l << " " << ost << "\n"; } for(auto x : graph[v]) { if(vis[x] == -1) { //cout << "DAS"; lvl[x] = new_l; vis[x] = ost; q.push(x); } } } for(int i = 1; i <= n; i++) { cout << lvl[i] << " "; } cout << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); read_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...