using System; using System.Collections.Generic; using System.Linq; namespace No326 { class MainClass { private class Edge { readonly int _first; public int First { get { return _first; } } readonly int _second; public int Second { get { return _second; } } public Edge(int first, int second) { _first = first; _second = second; } } private static void SwapPositions(List positions, List edges) { foreach (var edge in edges) { var temp = positions [edge.First - 1]; positions [edge.First - 1] = positions [edge.Second - 1]; positions [edge.Second - 1] = temp; } DumpCurrent (positions); } private static void DumpCurrent(List positions) { //Console.WriteLine ("current = " + String.Join (",", positions)); } public static void Main (string[] args) { var n = Convert.ToInt32 (Console.ReadLine ()); var k = Convert.ToInt32 (Console.ReadLine ()); List edges = new List (); for (int i = 0; i < k; i++) { var line = Console.ReadLine ().Split (' ').Select (_ => Convert.ToInt32 (_)).ToArray (); edges.Add(new Edge(line[0],line[1])); } var positions = Enumerable.Range (1, n).ToList (); SwapPositions (positions, edges); var targetLine = Console.ReadLine ().Split (' ').Select (_ => Convert.ToInt32 (_)).ToArray (); var addingList = new List (); for (int i = 0; i < n; i++) { var left = targetLine [i]; var index = positions.IndexOf (left); List list = new List (); for(int j = index; j > i;j--) { list.Add(new Edge(j + 1, j)); } SwapPositions(positions, list); addingList.AddRange(list); } Console.WriteLine(addingList.Count.ToString()); foreach(var edge in addingList) { Console.WriteLine (edge.First.ToString() + " " + edge.Second.ToString()); } } } }