結果

問題 No.429 CupShuffle
ユーザー htensai
提出日時 2019-11-19 20:53:15
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,010 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 1,914 ms
コンパイル使用メモリ 79,136 KB
実行使用メモリ 71,620 KB
最終ジャッジ日時 2024-10-04 07:21:43
合計ジャッジ時間 9,142 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int[] arrA = new int[k + 1];
		int[] arrB = new int[k + 1];
		for (int i = 1; i <= k; i++) {
		    if (i == x) {
		        sc.next();
		        sc.next();
		    } else {
		        arrA[i] = sc.nextInt();
		        arrB[i] = sc.nextInt();
		    }
		}
		int[] starts = new int[n + 1];
		int[] ends = new int[n + 1];
		for (int i = 1; i <= n; i++) {
		    starts[i] = i;
		    ends[i] = sc.nextInt();
		}
		for (int i = 1; i < x; i++) {
		    int tmp = starts[arrA[i]];
		    starts[arrA[i]] = starts[arrB[i]];
		    starts[arrB[i]] = tmp;
		}
		for (int i = k; i > x; i--) {
		    int tmp = ends[arrA[i]];
		    ends[arrA[i]] = ends[arrB[i]];
		    ends[arrB[i]] = tmp;
		}
		int first = 0;
		int second = 0;
		for (int i = 1; i <= n; i++) {
		    if (starts[i] != ends[i]) {
		        if (first == 0) {
		            first = i;
		        } else {
		            second = i;
		            break;
		        }
		    }
		}
		System.out.println(first + " " + second);
	}
}
0