結果

問題 No.1898 Battle and Exchange
ユーザー tentententen
提出日時 2022-04-11 14:30:21
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,381 bytes
コンパイル時間 2,946 ms
コンパイル使用メモリ 85,892 KB
実行使用メモリ 80,852 KB
最終ジャッジ日時 2024-05-09 02:00:06
合計ジャッジ時間 51,426 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
38,248 KB
testcase_01 AC 70 ms
38,692 KB
testcase_02 AC 73 ms
38,044 KB
testcase_03 AC 74 ms
38,284 KB
testcase_04 AC 107 ms
39,032 KB
testcase_05 AC 108 ms
39,036 KB
testcase_06 AC 148 ms
40,496 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 86 ms
38,608 KB
testcase_12 AC 154 ms
40,468 KB
testcase_13 AC 74 ms
38,216 KB
testcase_14 AC 135 ms
40,232 KB
testcase_15 AC 75 ms
38,300 KB
testcase_16 AC 121 ms
39,500 KB
testcase_17 AC 264 ms
46,052 KB
testcase_18 AC 669 ms
54,160 KB
testcase_19 AC 934 ms
55,856 KB
testcase_20 AC 664 ms
56,280 KB
testcase_21 AC 1,563 ms
74,320 KB
testcase_22 AC 84 ms
38,448 KB
testcase_23 AC 110 ms
39,216 KB
testcase_24 AC 110 ms
38,932 KB
testcase_25 AC 130 ms
39,448 KB
testcase_26 AC 74 ms
38,436 KB
testcase_27 AC 213 ms
43,672 KB
testcase_28 AC 227 ms
44,064 KB
testcase_29 AC 289 ms
46,556 KB
testcase_30 AC 168 ms
41,396 KB
testcase_31 AC 97 ms
38,884 KB
testcase_32 AC 502 ms
54,936 KB
testcase_33 AC 748 ms
62,312 KB
testcase_34 AC 509 ms
54,032 KB
testcase_35 AC 612 ms
57,196 KB
testcase_36 AC 548 ms
56,120 KB
testcase_37 AC 425 ms
50,668 KB
testcase_38 AC 2,604 ms
70,528 KB
testcase_39 AC 1,269 ms
75,488 KB
testcase_40 AC 2,458 ms
68,860 KB
testcase_41 AC 993 ms
66,784 KB
testcase_42 AC 282 ms
45,844 KB
testcase_43 AC 905 ms
67,516 KB
testcase_44 AC 91 ms
38,800 KB
testcase_45 AC 373 ms
48,352 KB
testcase_46 AC 962 ms
55,828 KB
testcase_47 AC 312 ms
46,896 KB
testcase_48 AC 308 ms
49,556 KB
testcase_49 AC 220 ms
43,760 KB
testcase_50 AC 210 ms
43,572 KB
testcase_51 AC 224 ms
44,308 KB
testcase_52 AC 248 ms
45,632 KB
testcase_53 AC 466 ms
52,476 KB
testcase_54 AC 543 ms
53,416 KB
testcase_55 AC 777 ms
54,824 KB
testcase_56 AC 503 ms
53,488 KB
testcase_57 AC 2,813 ms
76,720 KB
testcase_58 AC 1,765 ms
79,532 KB
testcase_59 AC 1,670 ms
75,956 KB
testcase_60 AC 2,046 ms
80,852 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