# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
64205 | gs14004 | 두 로봇 (KOI18_robot) | C++17 | 148 ms | 59748 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 <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
using lint = long long;
const int MAXN = 255555;
vector<pi> gph[MAXN];
vector<int> v;
int n, s, e;
int par[MAXN], pae[MAXN];
void dfs(int x, int p){
for(auto &i : gph[x]){
if(i.second != p){
par[i.second] = x;
pae[i.second] = i.first;
dfs(i.second, x);
}
}
}
int main(){
scanf("%d %d %d",&n,&s,&e);
if(s == e){
puts("0");
return 0;
}
for(int i=0; i<n-1; i++){
int x, y, v;
scanf("%d %d %d",&x,&y,&v);
gph[x].push_back(pi(v, y));
gph[y].push_back(pi(v, x));
}
dfs(s, -1);
while(e != s){
v.push_back(pae[e]);
e = par[e];
}
cout << accumulate(v.begin(), v.end(), 0) - *max_element(v.begin(), v.end()) << endl;
}
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... |