Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define NMAX 5010
  5. int G[NMAX][NMAX], Gr[NMAX],n,m,a[NMAX],x,y,p,Q[NMAX],nr;
  6.  
  7. ifstream f("castel.in");
  8. ofstream g("castel.out");
  9.  
  10. void load()
  11. {
  12. int i;
  13. f >> n >> m;
  14. for(i=1 ; i <= n; i++)
  15. {
  16. f >> x >> y;
  17. G[x][y]=G[y][x]=1; Gr[x]++; Gr[y]++;
  18. }
  19. f >> p;
  20. for(i=1; i <= p; i++){
  21. f >> x; a[x]++;
  22. }
  23. }
  24.  
  25. void special()
  26. {
  27. int i,j;
  28. for( i=1; i<=n; i++)
  29. for( j=1; j<=n; j++)
  30. {
  31. if ( Gr[i]%2==1 && Gr[j]%2==1 && a[i]!=0 && a[j]!=0 && i!=j){ G[i][j]++; }
  32. }
  33.  
  34. for(i=1; i <= n; i++){
  35. for(j=1; j <=n; j++)
  36. g << G[i][j]<<" ";
  37. g<<endl;
  38. }
  39. }
  40.  
  41. bool verif ()
  42. {
  43. int i;
  44. for ( i=1; i <=n; i++)
  45. if ( Gr[i]%2 == 1) return false;
  46. return true;
  47. }
  48.  
  49. void euler(int nod)
  50. {
  51. int i;
  52. for(i=1; i<= n; i++)
  53. {
  54. if(G[nod][i]!=0)
  55. {
  56. if(G[nod][i]==1){
  57. G[nod][i]=0;
  58. G[i][nod]=0;
  59. euler(i);
  60. }
  61. if(G[nod][i]==2)
  62. {
  63. G[nod][i]-=1; G[i][nod]-=1;
  64. euler(i);
  65. }
  66. }
  67. }
  68. Q[++nr]=nod;
  69. }
  70.  
  71. int main()
  72. {
  73. load();
  74. special();
  75. nr=0;
  76. euler(1);
  77.  
  78. for(int i=1; i<=nr; i++)
  79. g<<Q[i]<<" ";
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement