結果

問題 No.429 CupShuffle
ユーザー Tsukasa_Type
提出日時 2018-03-06 15:22:24
言語 Java
(openjdk 23)
結果
AC  
実行時間 968 ms / 2,000 ms
コード長 1,023 bytes
コンパイル時間 2,507 ms
コンパイル使用メモリ 80,544 KB
実行使用メモリ 69,748 KB
最終ジャッジ日時 2024-09-18 23:59:42
合計ジャッジ時間 9,061 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[k];
		int[] b = new int[k];
		String temp1,temp2;
		for (int i=0; i<k; i++) {
			if (i==x-1) {temp1=sc.next(); temp2=sc.next();}
			else {
				a[i] = sc.nextInt()-1;
				b[i] = sc.nextInt()-1;
			}
		}
		int[] end = new int[n];
		for (int i=0; i<n; i++) {
			end[i] = sc.nextInt();
		}
		int[] start = new int[n];
		for (int i=0; i<n; i++) {
			start[i] = i+1;
		}
		int temp;
		for (int i=0; i<x-1; i++) {
			temp = start[a[i]];
			start[a[i]] = start[b[i]];
			start[b[i]] = temp;
			
		}
		for (int i=k-1; i>=x; i--) {
			temp = end[a[i]];
			end[a[i]] = end[b[i]];
			end[b[i]] = temp;
			
		}
		
		List<Integer> list = new ArrayList<>();
		for (int i=0; i<n; i++) {
			if (start[i]!=end[i]) {list.add(i+1);}
		}
		
		out.println(list.get(0)+" "+list.get(1));
	}
}
0