結果

問題 No.26 シャッフルゲーム
ユーザー YamaKasaYamaKasa
提出日時 2018-04-20 00:36:23
言語 Java19
(openjdk 21)
結果
AC  
実行時間 169 ms / 5,000 ms
コード長 497 bytes
コンパイル時間 1,816 ms
コンパイル使用メモリ 70,816 KB
実行使用メモリ 55,976 KB
最終ジャッジ日時 2023-09-09 11:51:54
合計ジャッジ時間 4,031 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,704 KB
testcase_01 AC 120 ms
55,908 KB
testcase_02 AC 155 ms
55,504 KB
testcase_03 AC 132 ms
55,644 KB
testcase_04 AC 136 ms
55,720 KB
testcase_05 AC 153 ms
55,676 KB
testcase_06 AC 154 ms
55,756 KB
testcase_07 AC 136 ms
55,780 KB
testcase_08 AC 153 ms
55,976 KB
testcase_09 AC 169 ms
55,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		int []P = new int[M];
		int []Q = new int[M];
		for(int i = 0; i < M; i++) {
			P[i] = scan.nextInt();
			Q[i] = scan.nextInt();
		}
		scan.close();
		int ans = N;
		for(int i = 0; i < M; i++) {
			if(ans == P[i]) {
				ans = Q[i];
			}else if(ans == Q[i]){
				ans = P[i];
			}
		}
		System.out.println(ans);
	}
}
0