1 // CALCULAR EL LEXICOGRAF FIRST PATH EULERIANO DE UN GRAFO...
2 // SI LEN != C+1 ENTONCES; NO EXISTE DICHO CAMINO :)
21 fin
= fopen("fence.in", "r"); fout
= fopen("fence.out", "w");
22 vector
<pair
<int,int> > edge
[501];
24 fscanf(fin
, "%i", &C
);
27 fscanf(fin
,"%i %i", &a
, &b
);
28 edge
[a
].push_back(make_pair(b
,i
)), edge
[b
].push_back(make_pair(a
,i
));
34 if( edge
[1].size() %2 ==0)
35 for(i
=2;i
<=500;i
++) if(edge
[i
].size() % 2 ){
38 for(i
=1;i
<=500;i
++) sort(edge
[i
].begin(), edge
[i
].end());
39 // path[len++] = location;
40 int valor
[2000];memset(valor
, 0, sizeof(valor
));
44 for(i
=0;i
<edge
[location
].size();i
++){
45 int nodo
= edge
[location
][i
].first
;
46 if( valor
[edge
[location
][i
].second
] ) continue;
48 valor
[edge
[location
][i
].second
] = 1;
50 // path[len++] = nodo;
57 // printf("Holanda\n");
58 path
[len
++] = location
;
59 if( S
.size() == 0 ) break;
60 location
= S
.top(); S
.pop();
63 // printf("SIIIIIIII mmmm\n");
65 for(i
=len
-1;i
>=0;i
--) fprintf(fout
, "%i\n", path
[i
]);
67 // for(i=0;i<len;i++) fprintf(fout, "%i\n", path[i]);
68 // for(i=0;i<len;i++) printf("%i\n", path[i]);