# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
846335 | vjudge1 | Torrent (COI16_torrent) | C++17 | 62 ms | 11900 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |