// yukicoder: No.429 CupShuffle // 2019.6.9 bal4u #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } int p[100005], c[100005]; int a[100005], b[100005]; int main() { int i, N, K, X, t, ans[2]; N = in(), K = in(), X = in(); for (i = 1; i <= N; i++) p[i] = i; for (i = 1; i < X; i++) { int x = in(), y = in(); t = p[x], p[x] = p[y], p[y] = t; } for (i = 0; i < 4; i++) gc(); for (i = X+1; i <= K; i++) a[i] = in(), b[i] = in(); for (i = 1; i <= N; i++) c[i] = in(); for (i = K; i > X; i--) { t = c[a[i]], c[a[i]] = c[b[i]], c[b[i]] = t; } t = 0; for (i = 1; ; i++) { if (p[i] != c[i]) { ans[t++] = i; if (t == 2) break; } } printf("%d %d\n", ans[0], ans[1]); return 0; }