結果

問題 No.26 シャッフルゲーム
ユーザー matsuyoshi30matsuyoshi30
提出日時 2016-03-27 15:07:34
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 688 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 74,768 KB
実行使用メモリ 54,504 KB
最終ジャッジ日時 2024-04-10 03:12:55
合計ジャッジ時間 4,205 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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=0; i<m; i++) {
            p[i] = in.nextInt();
            q[i] = in.nextInt();
        }

        int temp = n;
        for(int i=0; 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