daily pastebin goal
18%
SHARE
TWEET

Untitled

a guest Dec 20th, 2018 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include<fstream>
  3. #include<vector>
  4. #include<deque>
  5. using namespace std;
  6. vector<int> v[11];
  7. void addedge();
  8. int main(){
  9.     int cont=0;
  10.     int visitato[11];
  11.     for(int i=0;i<11;i++)
  12.         visitato[i]=0;
  13.     addedge();
  14.     deque<int> d;
  15.     d.push_back(0);
  16.     int corrente=0;
  17.     int nododaraggiungere;
  18.     cin>>nododaraggiungere;
  19.     while(d.size()!=0&&corrente!=nododaraggiungere){
  20.         corrente=d[0];
  21.         d.pop_front();
  22.         if(visitato[corrente]==0){
  23.             cont++;
  24.             visitato[corrente]=1;
  25.             for(auto i:v[corrente]){
  26.                 d.push_back(i);
  27.             }
  28.         }
  29.     }
  30.     cout<<cont;
  31.    return 0;
  32. }
  33.  
  34. void addedge(){
  35.     v[0].push_back(1);
  36.     v[0].push_back(2);
  37.     v[2].push_back(0);
  38.     v[1].push_back(0);
  39.     v[1].push_back(3);
  40.     v[3].push_back(1);
  41.     v[2].push_back(6);
  42.     v[2].push_back(5);
  43.     v[2].push_back(4);
  44.     v[4].push_back(2);
  45.     v[5].push_back(2);
  46.     v[6].push_back(2);
  47.     v[3].push_back(7);
  48.     v[3].push_back(8);
  49.     v[3].push_back(9);
  50.     v[7].push_back(3);
  51.     v[8].push_back(3);
  52.     v[9].push_back(3);
  53.     v[5].push_back(10);
  54.     v[10].push_back(5);
  55. }
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