結果

問題 No.26 シャッフルゲーム
ユーザー matsuyoshi30matsuyoshi30
提出日時 2016-03-27 15:08:39
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 690 bytes
コンパイル時間 1,978 ms
コンパイル使用メモリ 74,164 KB
実行使用メモリ 54,516 KB
最終ジャッジ日時 2024-04-10 03:13:00
合計ジャッジ時間 4,174 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] p = new int[m];
        int[] q = new int[m];

        for(int i=1; i<=m; i++) {
            p[i] = in.nextInt();
            q[i] = in.nextInt();
        }

        int temp = n;
        for(int i=1; i<=m; i++) {
            if(p[i] != temp && q[i] != temp) continue;
            if(p[i] == temp) {
                temp = q[i];
            }
            if(q[i] == temp) {
                temp = p[i];
            }
        }

        System.out.println(temp);
    }
}
0