daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Dec 15th, 2018 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include<fstream>
  3. #include<vector>
  4. using namespace std;
  5. int main(){
  6.     ifstream in;
  7.     ofstream ou;
  8.     in.open("input.txt");
  9.     ou.open("output.txt");
  10.     int n;
  11.     in>>n;
  12.     int lati;
  13.     in>>lati;
  14.     int array[n];
  15.     int visitato[n];
  16.     for(int i=0;i<n;i++){
  17.         in>>array[i];
  18.         visitato[i]=0;
  19.     }
  20.     vector<int> v[n];
  21.     int a,b;
  22.     for(int i=0;i<lati;i++){
  23.        in>>a;
  24.        in>>b;
  25.        v[a].push_back(b);
  26.        v[b].push_back(a);
  27.     }
  28.     int cont=0;
  29.     vector<int> pila;
  30.     pila.push_back(0);
  31.     int corrente;
  32.     while(pila.size()!=0){
  33.        corrente=pila[0];
  34.        pila.erase(pila.begin());
  35.        if (visitato[corrente] == 0){
  36.             visitato[corrente] = 1;
  37.             cont+=array[corrente];
  38.             for (vector <int>::iterator i = v[corrente].begin(); i!=v[corrente].end(); i++)
  39.                     pila.push_back(*i);
  40.         }
  41.     }
  42.     ou<<cont;
  43.     return 0;
  44. }
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