/* -*- coding: utf-8 -*- * * 429.cc: No.429 CupShuffle - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ typedef pair pii; typedef stack spii; /* global variables */ int os[MAX_N], cs[MAX_N]; /* subroutines */ /* main */ int main() { int n, k, x; scanf("%d%d%d", &n, &k, &x); x--; for (int i = 0; i < n; i++) os[i] = i + 1; for (int i = 0; i < x; i++) { int ai, bi; scanf("%d%d", &ai, &bi); ai--, bi--; swap(os[ai], os[bi]); } string sa, sb; cin >> sa >> sb; spii sws; for (int i = x + 1; i < k; i++) { int ai, bi; scanf("%d%d", &ai, &bi); ai--, bi--; sws.push(pii(ai, bi)); } for (int i = 0; i < n; i++) cin >> cs[i]; while (! sws.empty()) { pii sw = sws.top(); sws.pop(); swap(cs[sw.first], cs[sw.second]); } //for (int i = 0; i < n; i++) printf("%d->%d\n", os[i], cs[i]); int a = -1, b = -1; for (int i = 0; i < n; i++) if (os[i] != cs[i]) { if (a < 0) a = i; else { b = i; break; } } printf("%d %d\n", a + 1, b + 1); return 0; }