Submission #1779179
Source Code Expand
import java.util.*; import java.io.*; public class Main { private static IO io = new IO(); public static void main(String[] args) { int n = io.nextInt(); int m = io.nextInt(); int d[][] = new int[n][n]; int INF = 1145141; for (int i = 0; i < n; i++) { Arrays.fill(d[i], INF); d[i][i] = 0; } for (int i = 0; i < m; i++) { int a = io.nextInt()-1; int b = io.nextInt()-1; int c = io.nextInt(); d[a][b] = d[b][a] = Math.min(d[a][b], c); } // ワーシャルフロイド for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]); } } } int ans = INF; for (int i = 0; i < n; i++) { int tmp = 0; for (int j = 0; j < n; j++) { tmp = Math.max(tmp, d[i][j]); } ans = Math.min(ans, tmp); } System.out.println(ans); } static class IO extends PrintWriter { private final InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; IO() { this(System.in); } IO(InputStream source) { super(System.out); this.in = source; } boolean hasNextByte() { if (ptr < buflen) return true; else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) return false; } return true; } int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } boolean isPrintableChar(int c) {return 33<=c &&c <=126;} void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;} boolean hasNext() { skipUnprintable(); return hasNextByte(); } long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) throw new NumberFormatException(); while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) return minus ? -n : n; else throw new NumberFormatException(); b = readByte(); } } int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public void close() { super.close(); try { in.close(); } catch (IOException ignored) { } } } }
Submission Info
Submission Time | |
---|---|
Task | D - バスと避けられない運命 |
User | creep04 |
Language | Java8 (OpenJDK 1.8.0) |
Score | 100 |
Code Size | 3437 Byte |
Status | AC |
Exec Time | 171 ms |
Memory | 23892 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
Set Name | Test Cases |
---|---|
All | sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 78 ms | 19284 KB |
sample_02.txt | AC | 77 ms | 18772 KB |
sample_03.txt | AC | 79 ms | 20692 KB |
test_01.txt | AC | 78 ms | 22356 KB |
test_02.txt | AC | 134 ms | 19540 KB |
test_03.txt | AC | 171 ms | 22996 KB |
test_04.txt | AC | 111 ms | 21076 KB |
test_05.txt | AC | 127 ms | 21120 KB |
test_06.txt | AC | 114 ms | 20000 KB |
test_07.txt | AC | 157 ms | 21600 KB |
test_08.txt | AC | 82 ms | 17108 KB |
test_09.txt | AC | 133 ms | 21140 KB |
test_10.txt | AC | 101 ms | 22064 KB |
test_11.txt | AC | 116 ms | 20784 KB |
test_12.txt | AC | 133 ms | 20732 KB |
test_13.txt | AC | 102 ms | 20688 KB |
test_14.txt | AC | 123 ms | 20768 KB |
test_15.txt | AC | 142 ms | 22352 KB |
test_16.txt | AC | 112 ms | 22832 KB |
test_17.txt | AC | 134 ms | 22560 KB |
test_18.txt | AC | 135 ms | 22432 KB |
test_19.txt | AC | 127 ms | 19232 KB |
test_20.txt | AC | 122 ms | 22320 KB |
test_21.txt | AC | 80 ms | 20948 KB |
test_22.txt | AC | 126 ms | 19232 KB |
test_23.txt | AC | 82 ms | 19796 KB |
test_24.txt | AC | 132 ms | 22100 KB |
test_25.txt | AC | 135 ms | 20436 KB |
test_26.txt | AC | 106 ms | 20688 KB |
test_27.txt | AC | 112 ms | 23892 KB |
test_28.txt | AC | 132 ms | 20820 KB |
test_29.txt | AC | 131 ms | 21076 KB |
test_30.txt | AC | 104 ms | 21844 KB |
test_31.txt | AC | 96 ms | 19540 KB |
test_32.txt | AC | 136 ms | 22100 KB |
test_33.txt | AC | 129 ms | 21588 KB |
test_34.txt | AC | 96 ms | 17492 KB |
test_35.txt | AC | 104 ms | 20180 KB |
test_36.txt | AC | 128 ms | 22996 KB |