#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
using namespace std;
namespace solve
{
const int maxn = 1e5 + 10;
typedef long long ll;
set<pair<int, int>, greater<pair<int, int>>> S, T;
int bel[maxn], del[maxn];
int a[maxn], m, n;
int u[maxn], v[maxn];
int qwq[maxn];
void main()
{
cin >> n >> m;
for (int i = 1; i <= n * 2; i++)
cin >> a[i];
for (int i = 1; i <= m; i++)
{
int x, y;
cin >> x >> y, bel[x] = i, bel[y] = i;
u[i] = x, v[i] = y;
}
int type, x = -1;
cin >> type;
type %= 2;
for (int t = 0; t < n * 2; t++, type ^= 1)
{
if (type == 0)
{
// cerr << "??????????" << x << endl;
cin >> x;
del[x] = 1;
}
else
{
if (x != -1 && bel[x] && !qwq[bel[x]])
{
int p = u[bel[x]], q = v[bel[x]];
int out = x == p ? q : p;
qwq[bel[x]] = 1;
cout << out << endl;
del[out] = 1;
del[x] = 1;
}
else
{
del[x] = 1;
int flag = 0;
for (int i = 1; i <= m; i++)
if (!del[u[i]] && !del[v[i]])
{
int x = u[i], y = v[i];
if (a[y] > a[x])
swap(x, y);
cout << x << endl;
del[x] = 1;
flag = 1;
qwq[i] = 1;
break;
}
if (flag == 0)
{
S.clear();
for (int i = 1; i <= n * 2; i++)
if (!del[i])
S.insert({a[i], i});
int x = S.begin()->second;
del[x] = 1;
cout << x << endl;
}
}
}
}
}
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0);
int T = 1;
// cin >> T;
while (T--)
solve::main();
}
1360A - Minimal Square | 467A - George and Accommodation |
893C - Rumor | 227B - Effective Approach |
1534B - Histogram Ugliness | 1611B - Team Composition Programmers and Mathematicians |
110A - Nearly Lucky Number | 1220B - Multiplication Table |
1644A - Doors and Keys | 1644B - Anti-Fibonacci Permutation |
1610A - Anti Light's Cell Guessing | 349B - Color the Fence |
144A - Arrival of the General | 1106A - Lunar New Year and Cross Counting |
58A - Chat room | 230A - Dragons |
200B - Drinks | 13A - Numbers |
129A - Cookies | 1367B - Even Array |
136A - Presents | 1450A - Avoid Trygub |
327A - Flipping Game | 411A - Password Check |
1520C - Not Adjacent Matrix | 1538B - Friends and Candies |
580A - Kefa and First Steps | 1038B - Non-Coprime Partition |
43A - Football | 50A - Domino piling |