-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1199.cpp
More file actions
49 lines (48 loc) · 1.03 KB
/
1199.cpp
File metadata and controls
49 lines (48 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
#define pii pair<int,int>
#define X first
#define Y second
using namespace std;
int n;
vector<int> adj[1000];
int graph[1000][1000];
int de[1000];
vector<int> circuit;
void dfs(int cur) {
while(adj[cur].size()) {
int nxt = adj[cur][adj[cur].size() - 1];
if(graph[cur][nxt] == 0) {
adj[cur].pop_back();
continue;
}
while(graph[cur][nxt]) {
graph[cur][nxt]--;
graph[nxt][cur]--;
dfs(nxt);
}
}
circuit.push_back(cur);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
int x; cin >> x;
graph[i][j] = x;
de[i] += x;
if(x) {
adj[i].push_back(j);
}
}
}
for(int i = 0; i < n; i++) {
if((de[i]) % 2) {
cout << -1;
return 0;
}
}
dfs(0);
for(int i : circuit) cout << i + 1 << " ";
}