# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
504812 | neonaht | Torrent (COI16_torrent) | C++14 | 170 ms | 25360 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define st first
#define nd second
#define ll int64_t
using namespace std;
const int SZ=3e5+7;
vector <int> node[SZ];
int dp[SZ],a,b;
void dfs(int v,int p) {
if(node[v].size()==1 && v!=a && v!=b) return ;
vector <int> went;
for(auto x:node[v]) {
if(x==a || x==b || x==p) continue;
dfs(x,v);
went.emplace_back(dp[x]);
}
int mx(0);
sort(went.begin(),went.end(),greater<int>());
for(int i=0;i<went.size();i++) mx=max(mx,went[i]+i+1);
dp[v]=mx;
return ;
}
int main(void) {
cin.tie(0)->ios::sync_with_stdio(false);
int n;
cin >> n >> a >> b;
for(int i=1,x,y;i<n;i++) {
cin >> x >> y;
node[x].emplace_back(y);
node[y].emplace_back(x);
}
dfs(a,-1);
dfs(b,-1);
cout << max(dp[a],dp[b]);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |