-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAllPartyMeet.cpp
95 lines (83 loc) · 1.95 KB
/
AllPartyMeet.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ ";
for(auto v : V) os << v << " ";
os << "]";
return os;
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
os << "{ ";
for(auto s:S) os<<s<<" ";
return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
os << "{ ";
for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
return os<<"}";
}
// Kevin Mathew T
// Birla Institute of Technology, Mesra
// GitHub - https://github.com/KevinMathewT
// CodeForces - https://codeforces.com/profile/KevinMathew
// CodeChef - https://www.codechef.com/users/KevinMathew
// HackerRank - https://www.hackerrank.com/KevinMathew?
ll n, a, b;
unordered_map<ll, unordered_map<ll, ll> > fren, notf;
void solve(){
cin >> n >> a >> b;
for(ll i=0;i<a;i++){
ll u, v;
cin >> u >> v;
fren[u][v] = 1;
fren[v][u] = 1;
}
for(ll i=0;i<a;i++){
ll u, v;
cin >> u >> v;
notf[u][v] = 1;
notf[v][u] = 1;
}
for(ll i=1;i<=n;i++){
vector<ll> sol(n + 1, i);
vector<ll> vis(n + 1, 0);
vis[i] = 1;
for(ll j=2;j<=n;j++){
cout << sol << "\n";
ll sz = sol.size();
for(ll k=1;k<=n;k++)
if(fren[sol.back()][k] == 1 && vis[k] == 0){
vis[k] = 1;
sol[j] = k;
break;
}
if(sol.size() == sz)
for(ll k=1;k<=n;k++)
if(vis[k] == 0 && notf[sol.back()][k] == 0){
vis[k] = 1;
sol[j] = k;
break;
}
}
if(sol.size() == n + 1){
cout << sol << "\n";
return;
}
}
cout << -1 << "\n";
}
int main()
{
freopen("input.txt", "r", stdin); //Comment
freopen("output.txt", "w", stdout); //this out.
ios::sync_with_stdio(false); //Not
cin.tie(NULL); //this.
cout.tie(0); //or this.
solve();
return 0;
}