using System; using System.Linq; namespace Yuki { class Program { static void Main(string[] args) { string[] ss = Console.ReadLine().Split(); int n = int.Parse(ss[0]); int k = int.Parse(ss[1]); int x = int.Parse(ss[2]); var c = new int[n]; for (int i = 1; i <= n; i++) { c[i - 1] = i; } for (int i = 0; i < x - 1; i++) { ss = Console.ReadLine().Split(); int a = int.Parse(ss[0]) - 1; int b = int.Parse(ss[1]) - 1; int w = c[a]; c[a] = c[b]; c[b] = w; } Console.ReadLine(); string[][] f = new string[k - x][]; for (int i = 0; i < k - x; i++) { f[i] = Console.ReadLine().Split(); } string[] s = Console.ReadLine().Split(); int[] c2 = s.Select(z => int.Parse(z)).ToArray(); for (int i = k - x - 1; i >= 0; i--) { int a = int.Parse(f[i][0]) - 1; int b = int.Parse(f[i][1]) - 1; int w = c2[a]; c2[a] = c2[b]; c2[b] = w; } int a1 = -1; int a2 = -1; for (int i = 0; i < n; i++) { if (c[i] != c2[i]) { if (a1 == -1) { a1 = i + 1; continue; } a2 = i + 1; break; } } if (a1 > a2) { Console.WriteLine("{0} {1}", a2, a1); } else { Console.WriteLine("{0} {1}", a1, a2); } } } }