Submission #1068658

#TimeUsernameProblemLanguageResultExecution timeMemory
1068658kunzaZa183Torrent (COI16_torrent)C++17
100 / 100
674 ms53832 KiB
#include <bits/stdc++.h> using namespace std; int main() { //cin.tie(0)->sync_with_stdio(0); int n,st,ed; cin>>n>>st>>ed; st--,ed--; vector<set<int>> adjlist(n); for(int i = 0; i < n - 1;i++) { int x,y; cin>>x>>y; x--,y--; adjlist[x].insert(y),adjlist[y].insert(x); } vector<int> bet(n); vector<int> path; function<void(int,int)> fp = [&](int cur,int par) { path.push_back(cur); if(cur==ed){ return; } for(auto a:adjlist[cur]) if(a!=par) { fp(a,cur); if(path.back()==ed) return; } path.pop_back(); }; fp(st,st); function<int(int,int)> dfs = [&](int cur,int par) { vector<int> vi; for(auto a:adjlist[cur]) if(a!=par) vi.push_back(dfs(a, cur)); sort(vi.begin(),vi.end(),greater<int>()); for(int i = 0; i < vi.size();i++) vi[i] += i+1; if(vi.empty()) return 0; return *max_element(vi.begin(),vi.end()); }; int maxans = n; int l =0 , r = path.size() - 2; while(l<=r) { int mid = (l+r)/2; int x = path[mid], y = path[mid + 1]; adjlist[x].erase(y),adjlist[y].erase(x); int a1 = dfs(st,st), a2 = dfs(ed,ed); maxans = min(maxans, max(a1,a2)); if(a1>a2) r = mid-1; else if(a1 <= a2) l= mid + 1; adjlist[x].insert(y),adjlist[y].insert(x); } cout<<maxans<<"\n"; }

Compilation message (stderr)

torrent.cpp: In lambda function:
torrent.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i = 0; i < vi.size();i++)
      |                    ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...