Created
August 16, 2017 08:18
-
-
Save koosaga/6219e5de7c9b5dc5b556716256937948 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <vector> | |
using namespace std; | |
vector<int> v; | |
int n,adj[1005][1005]; | |
void f(int x){ | |
for (int i=1; i<=n; i++) { | |
if(adj[x][i]){ | |
adj[x][i]--; | |
adj[i][x]--; | |
f(i); | |
v.push_back(i); // x->i 로 가는 에지 삽입 (편의상 끝점만) | |
} | |
} | |
} | |
int main(){ | |
int deg[1005] = {}; | |
scanf("%d",&n); | |
for (int i=1; i<=n; i++) { | |
for (int j=1; j<=n; j++) { | |
scanf("%d",&adj[i][j]); | |
deg[i] += adj[i][j]; | |
} | |
if(deg[i] % 2 == 1){ | |
puts("-1"); | |
return 0; | |
} | |
} | |
f(1); | |
v.push_back(1); | |
for (int i=v.size()-1; i>=0; i--) { | |
printf("%d ",v[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment