結果

問題 No.1898 Battle and Exchange
ユーザー ShirotsumeShirotsume
提出日時 2022-03-28 03:18:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,380 ms / 5,000 ms
コード長 3,132 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 80,960 KB
実行使用メモリ 85,188 KB
最終ジャッジ日時 2024-04-24 12:00:39
合計ジャッジ時間 54,704 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
41,340 KB
testcase_01 AC 118 ms
41,328 KB
testcase_02 AC 125 ms
41,548 KB
testcase_03 AC 134 ms
41,320 KB
testcase_04 AC 198 ms
42,820 KB
testcase_05 AC 182 ms
43,248 KB
testcase_06 AC 201 ms
44,552 KB
testcase_07 AC 207 ms
44,068 KB
testcase_08 AC 184 ms
42,508 KB
testcase_09 AC 458 ms
47,544 KB
testcase_10 AC 113 ms
41,140 KB
testcase_11 AC 144 ms
41,776 KB
testcase_12 AC 241 ms
46,536 KB
testcase_13 AC 110 ms
41,408 KB
testcase_14 AC 215 ms
46,192 KB
testcase_15 AC 124 ms
41,540 KB
testcase_16 AC 195 ms
43,744 KB
testcase_17 AC 402 ms
49,068 KB
testcase_18 AC 778 ms
61,192 KB
testcase_19 AC 1,016 ms
62,480 KB
testcase_20 AC 869 ms
62,196 KB
testcase_21 AC 1,817 ms
74,440 KB
testcase_22 AC 142 ms
42,252 KB
testcase_23 AC 199 ms
44,020 KB
testcase_24 AC 188 ms
43,188 KB
testcase_25 AC 194 ms
44,968 KB
testcase_26 AC 131 ms
41,532 KB
testcase_27 AC 301 ms
48,132 KB
testcase_28 AC 365 ms
48,752 KB
testcase_29 AC 528 ms
49,176 KB
testcase_30 AC 232 ms
46,356 KB
testcase_31 AC 169 ms
42,864 KB
testcase_32 AC 888 ms
62,744 KB
testcase_33 AC 1,140 ms
65,932 KB
testcase_34 AC 784 ms
61,892 KB
testcase_35 AC 939 ms
63,736 KB
testcase_36 AC 939 ms
63,016 KB
testcase_37 AC 598 ms
50,240 KB
testcase_38 AC 1,979 ms
84,176 KB
testcase_39 AC 1,226 ms
77,344 KB
testcase_40 AC 2,164 ms
79,716 KB
testcase_41 AC 1,273 ms
76,512 KB
testcase_42 AC 401 ms
48,316 KB
testcase_43 AC 1,238 ms
69,648 KB
testcase_44 AC 157 ms
42,148 KB
testcase_45 AC 526 ms
47,960 KB
testcase_46 AC 1,094 ms
61,164 KB
testcase_47 AC 448 ms
48,704 KB
testcase_48 AC 658 ms
49,984 KB
testcase_49 AC 350 ms
48,140 KB
testcase_50 AC 316 ms
47,772 KB
testcase_51 AC 307 ms
48,396 KB
testcase_52 AC 416 ms
47,232 KB
testcase_53 AC 742 ms
57,816 KB
testcase_54 AC 810 ms
64,256 KB
testcase_55 AC 863 ms
62,272 KB
testcase_56 AC 845 ms
62,980 KB
testcase_57 AC 2,380 ms
84,788 KB
testcase_58 AC 2,135 ms
85,188 KB
testcase_59 AC 1,832 ms
84,944 KB
testcase_60 AC 2,056 ms
75,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void upd(int A, int B, int C, int x){
		if (C < x){
			A = B;
			B = C;
			C = x;
		}
		else if (B < x){
			A = B;
			B = x;
		}
		else if(A < x){
			A = x;
		}
		return;
	}
	public static boolean solve(int n, int m, int minv, int[] a, int[] b, int[] c, int[] d, ArrayList<Integer>[] graph, int nowc){
		int A = 1;
		int B = 1;
		int C = nowc;
		if(d[0] >= A + B + C) return false;
		int x = c[0];
		if (C < x){
			A = B;
			B = C;
			C = x;
		}
		else if (B < x){
			A = B;
			B = x;
		}
		else if(A < x){
			A = x;
		}
		if (d[minv] >= A + B + C) return false;
		A = 1; B = 1;

		PriorityQueue<Pair> Q = new PriorityQueue<>();

		Q.add(new Pair(d[0], 0));

		boolean[] visit = new boolean[n];
		for(int i = 0; i < n; i++){
			visit[i] = false;
		}
		visit[0] = true;
		int sum, now;
		while(Q.size() > 0){
			Pair temp = Q.poll();
			sum = temp.time;
			now = temp.ver;
			if(sum >= A + B + C) return false;
			if(now == n - 1) return true;
			x = a[now];
			if (C < x){
				A = B;
				B = C;
				C = x;
			}
			else if (B < x){
				A = B;
				B = x;
			}
			else if(A < x){
				A = x;
			}
			x = b[now];
			if (C < x){
				A = B;
				B = C;
				C = x;
			}
			else if (B < x){
				A = B;
				B = x;
			}
			else if(A < x){
				A = x;
			}
			x = c[now];
			if (C < x){
				A = B;
				B = C;
				C = x;
			}
			else if (B < x){
				A = B;
				B = x;
			}
			else if(A < x){
				A = x;
			}
			for(int to: graph[now]){
				if (!visit[to]){
					visit[to] = true;
					Q.add(new Pair(d[to], to));
				}
			}
		}
		return false;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, m;
		n = sc.nextInt();
		m = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];

		ArrayList<Integer>[] graph = new ArrayList[n];
		for(int i = 0; i < n; i++){
			graph[i] = new ArrayList<Integer>();
		}
		int u, v;
		for(int i = 0; i < m ;i++){
			u = sc.nextInt();
			v = sc.nextInt();
			u--;
			v--;
			graph[u].add(v);
			graph[v].add(u);
		}
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}

		int[] d = new int[n];

		for(int i = 0; i < n; i++){
			d[i] = a[i] + b[i] + c[i];
		}
		int min , max;
		for(int i = 0; i < n; i++){
			min = Math.min(Math.min(a[i], b[i]), c[i]);
			max = Math.max(Math.max(a[i], b[i]), c[i]);
			a[i] = min;
			b[i] = d[i] - min - max;
			c[i] = max;
		}

		int mint = graph[0].get(0);
		for(int to: graph[0]){
			if(d[to] < d[mint]) mint = to;
		}

		int ok = 1000000000;
		int ng = 1;
		int mid;
		while(Math.abs(ok - ng) > 1){
			mid = (ok + ng) / 2;
			if(solve(n, m, mint, a, b, c, d, graph, mid)){
				ok = mid;
			}
			else ng = mid;
		}
		System.out.printf("%d %d %d\n", ok, 1, 1);

	}
}
class Pair implements Comparable<Pair>{
    int time;
    int ver;

    public Pair(int time, int ver) {
        this.time = time;
        this.ver = ver;
    }

    @Override
    public int compareTo(Pair p) {
        return Integer.compare(time, p.time);
    }
}
0