Submission #845323

#TimeUsernameProblemLanguageResultExecution timeMemory
845323vjudge1Birmingham (COCI20_birmingham)C++11
0 / 70
400 ms524288 KiB
#include <bits/stdc++.h> #define lg(a) (31 - __builtin_clz((a))) // #define endl ("\n") #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define vi vector<int> #define st first #define nd second #define all(aa) aa.begin(), aa.end() #define rall(aa) aa.rbegin(), aa.rend() #define forn(i, n) for(int i=0;i<n;i++) #define trav(e, x) for(auto& e:x) #define until(n, v) (int) (lower_bound(v.begin(), v.end(), n)-v.begin()) //# of elements < n #define after(n, v) (int) (v.end()-upper_bound(v.begin(), v.end(), n)) //# of elements > n #define sameas(n, v) (int) (upper_bound(v.begin(), v.end(), n) - lower_bound(v.begin(), v.end(), n)) //# of elements ==n typedef long long ll; using namespace std; /* */ int k; vector<vector<int>> edges; vector<int> vis; vector<int> ans; void bfs(int node, int d, priority_queue<pair<int, int>> next){ // cout<<"ENTERED BFS AT NODE: "<<node << " DISTANCE: "<< -d<<endl; vis[node] = 1; ans[node] = -d; for(auto e : edges[node]){ if(vis[e]==0){ next.push(mp(d-1, e)); } } if(next.size()==0) return; while(vis[next.top().second] and next.size()!=0) next.pop(); if(next.size()==0) return; pair<int, int> p = next.top(); next.pop(); bfs(p.second, p.first, next); } void solve(){ int n, m, q; cin>>n>>m>>q>>k; edges.resize(n+1); vis.resize(n+1); for(auto &e : vis) e = 0; ans.resize(n+1); for(int i=0;i<q;i++){ int a; cin>>a; edges[n].pb(a-1); } for(int i=0;i<m;i++){ int a, b; cin>>a>>b; edges[a-1].pb(b-1); edges[b-1].pb(a-1); } // for(int i=0;i<=n;i++){ // cout<<endl<<i<<"E "; // for(auto e : edges[i]) cout<<e<<' '; // } priority_queue<pair<int,int>> next; bfs(n, 1, next); // binary search to min a s.t. a(a+1)k/2 >= ans[i]; for(auto e : ans){ int l = 0, r= n+1, o=0; while(l<r){ int mid = (l+r)/2; if(mid*(mid+1)*k/2 < e){ l = mid+1; } else if(mid*(mid+1)*k/2 >= e){ o = mid; r = mid; } } cout<<o<<' '; } } int main(){ int test; // cin >> test; test =1; while (test--){ 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...