結果

問題 No.1898 Battle and Exchange
ユーザー tentententen
提出日時 2022-04-11 14:30:21
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,381 bytes
コンパイル時間 2,979 ms
コンパイル使用メモリ 88,132 KB
実行使用メモリ 91,572 KB
最終ジャッジ日時 2024-12-15 10:18:41
合計ジャッジ時間 42,445 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
50,908 KB
testcase_01 AC 65 ms
51,192 KB
testcase_02 AC 67 ms
51,456 KB
testcase_03 AC 67 ms
51,112 KB
testcase_04 AC 98 ms
51,980 KB
testcase_05 AC 98 ms
52,020 KB
testcase_06 AC 132 ms
53,188 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 79 ms
51,444 KB
testcase_12 AC 156 ms
53,164 KB
testcase_13 AC 73 ms
53,440 KB
testcase_14 AC 122 ms
52,476 KB
testcase_15 AC 72 ms
51,452 KB
testcase_16 AC 116 ms
52,288 KB
testcase_17 AC 228 ms
56,840 KB
testcase_18 AC 538 ms
65,144 KB
testcase_19 AC 714 ms
68,436 KB
testcase_20 AC 551 ms
67,560 KB
testcase_21 AC 1,219 ms
84,648 KB
testcase_22 AC 83 ms
51,404 KB
testcase_23 AC 101 ms
52,052 KB
testcase_24 AC 118 ms
51,764 KB
testcase_25 AC 121 ms
52,244 KB
testcase_26 AC 71 ms
51,368 KB
testcase_27 AC 190 ms
56,580 KB
testcase_28 AC 206 ms
56,416 KB
testcase_29 AC 266 ms
57,620 KB
testcase_30 AC 146 ms
53,680 KB
testcase_31 AC 86 ms
51,532 KB
testcase_32 AC 445 ms
64,628 KB
testcase_33 AC 668 ms
75,024 KB
testcase_34 AC 442 ms
64,792 KB
testcase_35 AC 504 ms
66,536 KB
testcase_36 AC 485 ms
66,796 KB
testcase_37 AC 356 ms
60,560 KB
testcase_38 AC 2,096 ms
80,488 KB
testcase_39 AC 825 ms
77,740 KB
testcase_40 AC 2,018 ms
86,800 KB
testcase_41 AC 788 ms
75,304 KB
testcase_42 AC 243 ms
56,884 KB
testcase_43 AC 672 ms
75,140 KB
testcase_44 AC 85 ms
51,584 KB
testcase_45 AC 319 ms
58,112 KB
testcase_46 AC 818 ms
65,528 KB
testcase_47 AC 280 ms
58,120 KB
testcase_48 AC 279 ms
56,924 KB
testcase_49 AC 190 ms
55,728 KB
testcase_50 AC 201 ms
56,644 KB
testcase_51 AC 200 ms
57,100 KB
testcase_52 AC 219 ms
57,148 KB
testcase_53 AC 357 ms
60,532 KB
testcase_54 AC 466 ms
62,528 KB
testcase_55 AC 600 ms
65,160 KB
testcase_56 AC 386 ms
63,200 KB
testcase_57 AC 2,021 ms
88,556 KB
testcase_58 AC 1,389 ms
87,800 KB
testcase_59 AC 1,441 ms
90,700 KB
testcase_60 AC 1,727 ms
91,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            graph.get(a).add(b);
            graph.get(b).add(a);
        }
        Card[] cards = new Card[n];
        for (int i = 0; i < n; i++) {
            cards[i] = new Card(i, sc.nextInt(), sc.nextInt(), sc.nextInt());
        }
        int left = 0;
        int right = Integer.MAX_VALUE / 2;
        PriorityQueue<Card> queue = new PriorityQueue<>();
        while (right - left > 1) {
            int x = (left + right) / 2;
            Card current = new Card(-1, 1, 1, x);
            queue.clear();
            queue.add(cards[0]);
            boolean[] visited = new boolean[n];
            boolean[] added = new boolean[n];
            added[0] = true;
            while (queue.size() > 0 && current.getSum() > queue.peek().getSum() && !visited[n - 1]) {
                Card c = queue.poll();
                if (visited[c.idx]) {
                    continue;
                }
                visited[c.idx] = true;
                current.exchange(c);
                for (int y : graph.get(c.idx)) {
                    if (!added[y]) {
                        queue.add(cards[y]);
                        added[y] = true;
                    }
                }
            }
            if (visited[n - 1]) {
                right = x;
            } else {
                left = x;
            }
        }
        System.out.println("1 1 " + right);
    }
    
    static class Card implements Comparable<Card> {
        int idx;
        int[] values;
        
        public Card(int idx, int a, int b, int c) {
            this.idx = idx;
            values = new int[]{a, b, c};
            sort();
        }
        
        public void sort() {
            Arrays.sort(values);
        }
        
        public int getSum() {
            int sum = 0;
            for (int x : values) {
                sum += x;
            }
            return sum;
        }
        
        public int compareTo(Card another) {
            return getSum() - another.getSum();
        }
        
        public void exchange(Card another) {
            if (values[0] < another.values[2]) {
                values[0] = another.values[2];
                sort();
            }
        }
     }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0