-
-
Save enzerr/04da81ca6d3a7ddc1843d3b2aefef285 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
const int maxn = 1e4 + 5; | |
int dist[maxn]; | |
vector<pair<int, int>> adj[maxn]; | |
void dfs(int x, int pai){ | |
for(auto[v, w] : adj[x]) if(v!=pai) | |
dist[v] = dist[x]+w, dfs(v, x); | |
} | |
int main(){ | |
int n, ini, fim; cin >> n >> ini >> fim; | |
for(int i = 0; i < n-1; i++){ | |
int a, b, c; cin >> a >> b >> c; | |
adj[a].push_back({b, c}); | |
adj[b].push_back({a, c}); | |
} | |
dfs(ini, ini); | |
cout << dist[fim] << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment