Advertisement
Guest User

Untitled

a guest
Sep 18th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <utility>
  4. using namespace std;
  5. typedef pair<int,int> pii;
  6. vector<int> bio[102];
  7. vector<pii> sus[102];
  8. int nako[102],kol[102];
  9.  
  10. int n,m,a,b,i,br,st,jel;
  11.  
  12. struct dpar{int a1,g1,b1,g2;};
  13.  
  14. dpar joj[102];
  15.  
  16.  
  17. void euler(int cur){
  18.    
  19.    
  20.     while( nako[cur]  < sus[cur].size() ){
  21.        
  22.         int z=sus[cur][  nako[cur] ].first;
  23.         int ka=sus[cur][ nako[cur] ].second;
  24.        
  25.         if(!bio[  cur  ][ nako[cur] ]  ){
  26.            
  27.             bio[joj[ka].a1][joj[ka].g1]=1;
  28.             bio[joj[ka].b1][joj[ka].g2]=1;
  29.        
  30.             nako[cur]++;
  31.            
  32.             euler(z);
  33.             if(!jel)cout<<endl<<"Start: "<<z<<endl;
  34.             jel++;
  35.             cout<<cur<<endl;
  36.            
  37.         }
  38.        
  39.         nako[cur]++;
  40.        
  41.     }
  42.    
  43. }
  44.  
  45.  
  46. int main(){
  47.  
  48.  
  49. cin>>n>>m;
  50.  
  51. st=1;
  52.  
  53. for(i=1;i<=m;i++){
  54.     cin>>a>>b;
  55.    
  56.     joj[i].a1=a,joj[i].g1=sus[a].size();
  57.     joj[i].b1=b,joj[i].g2=sus[b].size();
  58.    
  59.     bio[a].push_back(0);
  60.     bio[b].push_back(0);
  61.     sus[a].push_back(pii(b,i));
  62.     sus[b].push_back(pii(a,i));
  63. }
  64.  
  65. for(i=1;i<=n;i++){
  66.     if(sus[i].size()&1)br++,st=i;
  67. }
  68.  
  69. if(br>2){
  70.     cout<<"Nema Eulerske staze"<<endl;
  71.     return 0;
  72. }
  73. if(br==2)cout<<"Eulerov put"<<endl;
  74. else cout<<"Eulerov ciklus"<<endl;
  75. euler(st);
  76.  
  77.    
  78.    return 0;
  79. }
  80.  
  81. /*
  82. 7 12
  83. 1 5
  84. 1 2
  85. 1 6
  86. 1 4
  87. 5 2
  88. 2 6
  89. 6 4
  90. 6 3
  91. 2 3
  92. 4 3
  93. 4 7
  94. 3 7
  95. kucica:
  96. 5 6
  97. 1 2
  98. 1 3
  99. 1 5
  100. 5 2
  101. 2 4
  102. 3 4
  103. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement