Submission #246162

#TimeUsernameProblemLanguageResultExecution timeMemory
246162alradBirmingham (COCI20_birmingham)C++17
70 / 70
132 ms10616 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() const int N = 1e5 + 2; vector<vector<int> > g(N , vector<int>()); int main() { #ifdef judge ifstream cin("input.txt"); #endif // judge ios_base :: sync_with_stdio(0); cin.tie(0) , cout.tie(0); int n , m , que , k; cin >> n >> m >> que >> k; queue<int> q; vector<int> starts(que) , d(n + 1 , 0); vector<bool> used(n + 1 , false); for (int i = 0; i < que; i++) { cin >> starts[i]; q.push(starts[i]); used[starts[i]] = true; } for (int i = 0; i < m; i++) { int u , v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } while (!q.empty()) { int v = q.front(); q.pop(); for (int to : g[v]) { if (!used[to]) { used[to] = true; q.push(to); d[to] = d[v] + 1; } else if (d[v] + 1 < d[to]) { q.push(to); d[to] = d[v] + 1; } } } auto getDay = [&](int dist) { int res = 0 , temp = 1; while (res < dist) { res += (temp * k); temp++; } return temp - 1; }; for (int i = 1; i <= n; i++) { if (d[i] != 0) { cout << getDay(d[i]) << " "; } else { cout << 0 << " "; } } 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...