SHARE
TWEET

visitados

a guest Feb 14th, 2020 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1e5;
  5. vector< pair<int, int> > g[N+5];
  6. int visitados[N+5];
  7. int b; // chegada
  8. int INF = 0x3f3f3f3f;
  9. int DFS(int a){
  10.     visitados[a] = 1;
  11.     if(a == b) return 0;
  12.     int ans = INF ;
  13.     for(int i = 0; i < g[a].size(); i++){
  14.         int vizinho = g[a][i].first;
  15.     cout << vizinho << endl;
  16.         if(visitados[vizinho] == 0){
  17.             ans = min(ans, DFS(vizinho)+g[a][i].second);
  18.         }
  19.     }
  20.     return ans;
  21. }
  22.  
  23.  
  24.  
  25. int main(){
  26.     int n, a, b;
  27.     cin >> n >> a >> b;
  28.     for(int i = 1; i <= n-1; i++ ){            //n-1 arestas indicando arvore
  29.         int x, y, p;                       // peso da aresta
  30.         cin >> x >> y >> p;
  31.         g[x].push_back(make_pair(y,p)); g[y].push_back(make_pair(x,p));
  32.     }
  33.     cout << DFS(a) << endl; // guarda a partida;
  34.     return 0;
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top