-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path687A.cpp
More file actions
77 lines (59 loc) · 1.18 KB
/
687A.cpp
File metadata and controls
77 lines (59 loc) · 1.18 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <bits/stdc++.h>
using namespace std;
int tipo[1000100];
vector <int> grafo[1000100];
bool passou[1000100];
bool errado;
void dfs(int v,int t){
passou[v] = true;
tipo[v] = t;
//cout << "TIPO[" << v << "] = " << t << endl;
for(int i=0;i<grafo[v].size();i++){
int adj = grafo[v][i];
if(!passou[adj]){
dfs(adj,1-t);
}else if(passou[adj] && tipo[adj]==tipo[v]){
//cout << "ARESTA " << v << " " << adj << endl;
errado = true;
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin >> n >> m;
for(int i=0;i<m;i++){
int a,b;cin >> a >> b;
grafo[a].push_back(b);
grafo[b].push_back(a);
}
for(int i=1;i<=n;i++){
if(!passou[i]){
dfs(i,0);
}
}
if(errado){
cout << -1 << endl;
return 0;
}
vector <int> ans1,ans2;
for(int i=1;i<=n;i++){
if(tipo[i]){
ans1.push_back(i);
}else{
ans2.push_back(i);
}
}
cout << ans1.size() << endl;
for(int i=0;i<ans1.size();i++){
cout << ans1[i] << " ";
}
cout << endl;
cout << ans2.size() << endl;
for(int i=0;i<ans2.size();i++){
cout << ans2[i] << " ";
}
cout << endl;
return 0;
}