Submission #1145243

#TimeUsernameProblemLanguageResultExecution timeMemory
1145243calisovradu새로운 문제 (POI13_luk)C++20
30 / 100
409 ms19184 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<int>> v; vector<int> depth; vector<bool> checked; int n,maxim=0; long long crews; bool ok=true; void bfs(){ deque <pair<int,long long>> q; deque <int> checkq; q.push_back({1,0}); checked[1]=true; while(!q.empty()){ int node = q.front().first; long long left = q.front().second+crews; q.pop_front(); for(int i=0;i<v[node].size();i++){ int newnode = v[node][i]; if(checked[newnode]==false){ checked[newnode]=true; checkq.push_back(newnode); left--; } } if(left<0){ ok=false; break; } while(!checkq.empty()){ q.push_back({checkq.front(),left}); checkq.pop_front(); } } } bool verif(long long mij){ ok = true; crews=mij; bfs(); if(ok==true) return true; return false; } void fix(){ for(int i=1;i<=n;i++) checked[i]=false; } int main() { cin>>n; v.resize(n+1); depth.resize(n+1); checked.resize(n+1); for(int i=1;i<=n-1;i++){ int a,b; cin>>a>>b; v[a].push_back(b); v[b].push_back(a); } depth[1]=1; queue<int> q; q.push(1); while(!q.empty()){ int nod = q.front(); q.pop(); for(int i=0;i<v[nod].size();i++){ int newnod = v[nod][i]; if(depth[newnod]==0){ depth[newnod]=depth[nod]+1; q.push(newnod); } } } long long l=0,r=n,mij,corect=n; while(l<=r){ fix(); mij=(l+r)/2; bool res = verif(mij); if(res==true){ corect=min(mij,corect); r=mij-1; }else l=mij+1; } cout<<corect; }
#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...