daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Jun 19th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. typedef vector<bool> VB;
  6. typedef vector<VB> VVB;
  7. typedef vector<int> VI;
  8.  
  9. void escriu(VI& cami){
  10.     cout<<"(";
  11.     for(int i=0;i<cami.size();++i){
  12.         if(i>0)cout<<",";
  13.         cout<<cami[i];
  14.     }
  15.     cout<<")"<<endl;
  16. }      
  17.  
  18. void rec(VB& usat, VVB& m, VI& cami, int p, int maxp, int num, bool& trobat){
  19.     if(p==maxp+1){
  20.         escriu(cami);
  21.         trobat=true;
  22.         return;
  23.     }
  24.     for(int j=0;j<m.size();++j){
  25.         if(m[num][j] and not usat[j]){
  26.             cami[p]=j+1;
  27.             usat[j]=1;
  28.             rec(usat,m,cami,p+1,maxp,j,trobat);
  29.             usat[j]=0;
  30.         }
  31.     }
  32. }
  33.  
  34.  
  35. int main(){
  36.     int n,p;
  37.     bool fi=false;
  38.     while(not fi){
  39.         cin>>n>>p;
  40.         VVB m(n,VB(n));
  41.         int k;
  42.         for(int i=0;i<n;++i)
  43.             for(int j=0;j<n;++j){
  44.                 cin>>k;
  45.                 m[i][j]=k;
  46.             }
  47.         VI cami(p+1);
  48.         VB usat(n);
  49.         usat[0]=1;
  50.         cami[0]=1;
  51.         bool trobat=false;
  52.         rec(usat,m,cami,1,p,0,trobat);
  53.         if(not trobat)cout<<"no walk of length "<<p;
  54.         if(cin>>n and n==-9999)cout<<endl;
  55.         else fi=true;
  56.     }
  57. }
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