Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define NMAX 5010
- int G[NMAX][NMAX], Gr[NMAX],n,m,a[NMAX],x,y,p,Q[NMAX],nr;
- ifstream f("castel.in");
- ofstream g("castel.out");
- void load()
- {
- int i;
- f >> n >> m;
- for(i=1 ; i <= n; i++)
- {
- f >> x >> y;
- G[x][y]=G[y][x]=1; Gr[x]++; Gr[y]++;
- }
- f >> p;
- for(i=1; i <= p; i++){
- f >> x; a[x]++;
- }
- }
- void special()
- {
- int i,j;
- for( i=1; i<=n; i++)
- for( j=1; j<=n; j++)
- {
- if ( Gr[i]%2==1 && Gr[j]%2==1 && a[i]!=0 && a[j]!=0 && i!=j){ G[i][j]++; }
- }
- for(i=1; i <= n; i++){
- for(j=1; j <=n; j++)
- g << G[i][j]<<" ";
- g<<endl;
- }
- }
- bool verif ()
- {
- int i;
- for ( i=1; i <=n; i++)
- if ( Gr[i]%2 == 1) return false;
- return true;
- }
- void euler(int nod)
- {
- int i;
- for(i=1; i<= n; i++)
- {
- if(G[nod][i]!=0)
- {
- if(G[nod][i]==1){
- G[nod][i]=0;
- G[i][nod]=0;
- euler(i);
- }
- if(G[nod][i]==2)
- {
- G[nod][i]-=1; G[i][nod]-=1;
- euler(i);
- }
- }
- }
- Q[++nr]=nod;
- }
- int main()
- {
- load();
- special();
- nr=0;
- euler(1);
- for(int i=1; i<=nr; i++)
- g<<Q[i]<<" ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement