-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.cpp
76 lines (69 loc) · 1.11 KB
/
C.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
#include "bits/stdc++.h"
using namespace std;
typedef pair <int, int> pii;
int n, m;
int p[3111];
int a[3111];
bool vis[3111];
int main(int argc, char const *argv[])
{
int n, m;
cin >> n >> m;
for(int i = 1; i <= n+n; i++) {
cin >> a[i];
}
for(int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
p[x] = y;
p[y] = x;
}
int t;
cin >> t;
t %= 2;
int last = 0;
while(true) {
bool good = false;
for(int i = 1; i <= n+n; i++) {
if(vis[i] == false) {
good = true;
break;
}
}
if(good == false) break;
if(t == 1) {
if(p[last] > 0 && !vis[p[last]]) {
cout << p[last] << endl;
last = p[last];
} else {
int opt = -1;
for(int i = 1; i <= n+n; i++) {
if(!vis[i] && p[i] > 0) {
if(opt == -1 || a[i] > a[opt]) {
opt = i;
}
}
}
if(opt == -1) {
opt = -1;
for(int i = 1; i <= n+n; i++) {
if(!vis[i]) {
if(opt == -1 || a[i] > a[opt]) {
opt = i;
}
}
}
}
cout << opt << endl;
last = opt;
}
} else {
int x;
cin >> x;
last = x;
}
vis[last] = true;
t ^= 1;
}
return 0;
}