# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
846335 | vjudge1 | Torrent (COI16_torrent) | C++17 | 62 ms | 11900 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
vector<int> graph[100001];
int visited[100001];
int dfs(int node, int parent) {
int maxTime = 0;
for(int i = 0; i < graph[node].size(); i++) {
int nextNode = graph[node][i];
if(nextNode == parent) continue;
int time = dfs(nextNode, node) + 1;
maxTime = max(maxTime, time);
}
return maxTime;
}
int main() {
int n, a, b;
cin >> n >> a >> b;
for(int i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
graph[x].push_back(y);
graph[y].push_back(x);
}
int timeA = dfs(a, -1);
int timeB = dfs(b, -1);
int totalTime = timeA + timeB;
cout << totalTime << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |