Submission #328194

#TimeUsernameProblemLanguageResultExecution timeMemory
328194poom2904Torrent (COI16_torrent)C++11
69 / 100
140 ms25452 KiB
#include <bits/stdc++.h> using namespace std; int n,a,b; int x,y; vector<int> edge[300001]; stack<int> stk; vector<int> instk(300001,false); vector<int> dis(300001,0); int main() { ios_base::sync_with_stdio(false);cin.tie(0); cin>>n>>a>>b; for(int i=1;i<n;i++) { cin>>x>>y; edge[x].push_back(y); edge[y].push_back(x); } queue<int> q; q.push(a); q.push(b); stk.push(a); stk.push(b); instk[a]=instk[b]=true; while(!q.empty()) { int u = q.front(); q.pop(); for(auto v :edge[u])if(!instk[v]) { stk.push(v); instk[v]=true; q.push(v); } } while(!stk.empty()) { int u = stk.top(); stk.pop(); instk[u]=false; vector<int> vec; for(auto v : edge[u])if(!instk[v] && v!=a && v!=b)vec.push_back(dis[v]); sort(vec.begin(),vec.end(),greater<int>()); int max_t=0; for(int i=0;i<vec.size();i++)max_t=max(max_t,vec[i]+i+1); dis[u]=max_t; } cout<<max(dis[a],dis[b]); return 0; }

Compilation message (stderr)

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