Submission #845656

#TimeUsernameProblemLanguageResultExecution timeMemory
845656vjudge1Birmingham (COCI20_birmingham)C++11
35 / 70
379 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(next.size()!=0 and vis[next.top().second]) 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); for(int i=0;i<n;i++){ ll l = 0, r= n+1, o=0; while(l<r){ int mid = (l+r)/2; if(1ll*mid*(mid+1)*k/2 < ans[i]){ l = mid+1; } else if(1ll*mid*(mid+1)*k/2 >= ans[i]){ 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...