# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
328194 | 2020-11-15T16:54:20 Z | poom2904 | Torrent (COI16_torrent) | C++11 | 140 ms | 25452 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 9708 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 132 ms | 25324 KB | Output is correct |
2 | Correct | 135 ms | 25452 KB | Output is correct |
3 | Correct | 122 ms | 25196 KB | Output is correct |
4 | Correct | 125 ms | 25068 KB | Output is correct |
5 | Correct | 140 ms | 24940 KB | Output is correct |
6 | Correct | 124 ms | 25216 KB | Output is correct |
7 | Correct | 116 ms | 25068 KB | Output is correct |