# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
63170 | kjp4155 | 두 로봇 (KOI18_robot) | C++17 | 171 ms | 11644 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 <stdio.h>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;
int N,A,B;
vector<pair<int,int>> E[100500];
// dist는 루트로부터 해당 정점까지 거리를 저장하는 배열
// mx는 루트로부터 해당 정점까지 경로상 가장 긴 통로의 길이를 저장하는 배열
int dist[100500], mx[100500];
bool vis[100500];
void dfs(int node, int d, int m){
dist[node] = d;
mx[node] = m;
vis[node] = true;
for(pair<int,int> e : E[node]){
if( !vis[e.first] ) dfs(e.first, d + e.second, max(m, e.second) );
}
}
int main(){
scanf("%d%d%d",&N,&A,&B);
for(int i=1;i<=N-1;i++){
int x,y,z; scanf("%d%d%d",&x,&y,&z);
E[x].push_back(make_pair(y,z));
E[y].push_back(make_pair(x,z));
}
dfs(A,0,0);
printf("%d\n",dist[B]-mx[B]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |