Submission #731407


Source Code Expand

import java.io.*;
import java.util.*;
public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args) throws IOException{
		MyScanner sc = new MyScanner();
		PriorityQueue<Vertex> que = new PriorityQueue<>();
		int N = sc.nextInt(), M =sc.nextInt(), T = sc.nextInt();
		ArrayList<Edge> es[] = new ArrayList[N+1];
		ArrayList<Edge> es2[] = new ArrayList[N+1];
		
		int[] A = new int[N+1];
		for (int i = 1; i <= N; i++){
			A[i] = sc.nextInt();
			es[i] = new ArrayList<Edge>();
			es2[i] = new ArrayList<Edge>();
		}

//		input edges
		int a, b, c;
		for (int i = 0; i < M; i++){
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextInt();
			es[a].add(new Edge(b,(long)c));
			es2[b].add(new Edge(a,(long)c));
		}
	
		long max = A[1] * T;
		if (N==1){
			System.out.println(max);
			return;
		}
		
//		go!
		long shortest_go[] = dijkstra(N, es, 1);
//		back!
		long shortest_back[] = dijkstra(N, es2, 1);
		long this_cost;
//		calculate the treature		
		for (int i = 2; i <=N; i++){
			this_cost = (T - shortest_go[i] - shortest_back[i]) * A[i];
			if (this_cost > max)
				max = this_cost;
		}

		System.out.println(max);
		
	}
	
	static long[] dijkstra(int N, ArrayList<Edge> es[], int start){
		PriorityQueue<Vertex> pq = new PriorityQueue<>();
		long[] shortest = new long[N+1];
		Arrays.fill(shortest, Long.MAX_VALUE);
		shortest[start] = 0;

		pq.add(new Vertex(start, 0));
		while(!pq.isEmpty()){
			Vertex v = pq.poll();
			for (Edge e : es[v.no]){
				long d = e.dist + v.dist;
				if (d < shortest[e.to]){
					shortest[e.to] = d;
					pq.add(new Vertex(e.to, d));
				}
			}
		}

		return shortest;
	}
	
	static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
	
	static class Vertex implements Comparable<Vertex>{
		int no;
		long dist;
		Vertex (int no, long dist){
			this.no = no;
			this.dist = dist;
		}
		@Override
		public int compareTo(Vertex o) {
			if (this.dist - o.dist > 0)
				return 1;
			else
				return 0;
		}
	}

	static class Edge{
		int to;
		long dist;
		Edge(int to, long dist){
			this.to = to;
			this.dist = dist;
		}
	}

	static class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}
	
}


Submission Info

Submission Time
Task D - トレジャーハント
User haqishen
Language Java7 (OpenJDK 1.7.0)
Score 0
Code Size 3184 Byte
Status WA
Exec Time 3159 ms
Memory 44264 KiB

Compile Error

Note: ./Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 50 0 / 50
Status
AC × 3
AC × 15
WA × 5
AC × 20
WA × 21
TLE × 1
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
Subtask1 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 50_small_01.txt, 50_small_02.txt, 50_small_03.txt, 50_small_04.txt, 50_small_05.txt, 50_small_06.txt, 50_small_07.txt, 50_small_08.txt, 50_small_09.txt, 50_small_10.txt, 60_hand_01.txt, 60_hand_02.txt, 60_hand_03.txt, 60_hand_04.txt, 70_max_01.txt, 70_max_02.txt, 70_max_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 10_rand_06.txt, 10_rand_07.txt, 10_rand_08.txt, 10_rand_09.txt, 10_rand_10.txt, 10_rand_12.txt, 10_rand_13.txt, 30_max_01.txt, 30_max_02.txt, 30_max_03.txt, 30_max_04.txt, 30_max_05.txt, 30_max_06.txt, 40_corner_01.txt, 40_corner_02.txt, 40_corner_03.txt, 40_corner_04.txt, 50_small_01.txt, 50_small_02.txt, 50_small_03.txt, 50_small_04.txt, 50_small_05.txt, 50_small_06.txt, 50_small_07.txt, 50_small_08.txt, 50_small_09.txt, 50_small_10.txt, 60_hand_01.txt, 60_hand_02.txt, 60_hand_03.txt, 60_hand_04.txt, 70_max_01.txt, 70_max_02.txt, 70_max_03.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 171 ms 7636 KiB
00_example_02.txt AC 166 ms 7632 KiB
00_example_03.txt AC 168 ms 7764 KiB
10_rand_01.txt WA 218 ms 10708 KiB
10_rand_02.txt WA 339 ms 16464 KiB
10_rand_03.txt WA 236 ms 11088 KiB
10_rand_04.txt WA 208 ms 9940 KiB
10_rand_05.txt WA 220 ms 11600 KiB
10_rand_06.txt WA 226 ms 12244 KiB
10_rand_07.txt WA 239 ms 13652 KiB
10_rand_08.txt WA 217 ms 10836 KiB
10_rand_09.txt WA 224 ms 12752 KiB
10_rand_10.txt WA 207 ms 9492 KiB
10_rand_12.txt WA 745 ms 24232 KiB
10_rand_13.txt WA 605 ms 23520 KiB
30_max_01.txt TLE 3159 ms 30596 KiB
30_max_02.txt WA 1280 ms 33044 KiB
30_max_03.txt AC 1987 ms 26384 KiB
30_max_04.txt WA 453 ms 32596 KiB
30_max_05.txt WA 453 ms 31268 KiB
30_max_06.txt WA 453 ms 31492 KiB
40_corner_01.txt AC 601 ms 43836 KiB
40_corner_02.txt AC 614 ms 43564 KiB
40_corner_03.txt AC 606 ms 43808 KiB
40_corner_04.txt AC 726 ms 44264 KiB
50_small_01.txt AC 188 ms 8404 KiB
50_small_02.txt AC 171 ms 7764 KiB
50_small_03.txt WA 175 ms 7636 KiB
50_small_04.txt AC 173 ms 7764 KiB
50_small_05.txt AC 213 ms 8852 KiB
50_small_06.txt AC 202 ms 8532 KiB
50_small_07.txt WA 178 ms 7764 KiB
50_small_08.txt WA 176 ms 7632 KiB
50_small_09.txt AC 177 ms 7764 KiB
50_small_10.txt AC 177 ms 7764 KiB
60_hand_01.txt WA 169 ms 7636 KiB
60_hand_02.txt AC 170 ms 7764 KiB
60_hand_03.txt WA 175 ms 7636 KiB
60_hand_04.txt AC 171 ms 7764 KiB
70_max_01.txt AC 300 ms 12912 KiB
70_max_02.txt AC 324 ms 13036 KiB
70_max_03.txt AC 320 ms 12848 KiB