Submission #845171

#TimeUsernameProblemLanguageResultExecution timeMemory
845171vjudge1Birmingham (COCI20_birmingham)C++17
70 / 70
159 ms12628 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define int int64_t #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define F first #define S second #define I insert #define PB push_back #define POB pop_back #define sqr(a) ((a) * (a)) #define P pop #define max3(a, b, c) (max(a, max(b, c))) #define max4(a, b, c, d) (max(max(a, b), max(c, d))) #define min3(a, b, c) (min(a, min(b, c))) #define min4(a, b, c, d) (min(min(a, b), min(c, d))) #define MOD 1000000007 #define mod 998244353 #define tm ((l) + (r)) / 2 int binpow(int a, int p, int m = MOD) { int ans = 1; while (p) { if (p & 1) ans = ((ans % m) * (a % m)) % m; a = sqr(a) % m; p >>= 1; } return ans; } int n, m, q, k; vector<int> meet, dist; vector<vector<int>> adj; vector<bool> vis; void bfs(int s = 0) { vis[s] = true; queue<int> q; q.push(s); dist[s] = -1; while (!q.empty()) { int u = q.front(); q.pop(); for (auto x : adj[u]) { if (vis[x]) continue; vis[x] = true; dist[x] = dist[u] + 1; q.push(x); } } } int f(int a) { return ((a * (a + 1)) / 2) * k; } void solve() { cin >> n >> m >> q >> k; for (int i = 0; i < q; i++) { int tmp; cin >> tmp; meet.PB(tmp); } adj.assign(n + 1, {}); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; adj[a].PB(b); adj[b].PB(a); } for (int i = 0; i < q; i++) { adj[0].PB(meet[i]); adj[meet[i]].PB(0); } dist.assign(n + 1, 0); vis.assign(n + 1, false); bfs(); for (int i = 1; i <= n; i++) { int l = 0, r = dist[i]; while (r - l > 1) { if (f(tm) >= dist[i]) r = tm; else l = tm + 1; } if (f(l) >= dist[i]) cout << l << ' '; else cout << r << ' '; } } int32_t main() { int t = 1; // cin >> t; while (t--) { solve(); } }
#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...