結果

提出番号 1991
提出者 tanzaku
言語 Java
提出日時 2018-08-04 14:51:28
問題名 (73)観光計画
結果 MLE
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 348ms 174000KB
2 AC 100% 439ms 233744KB
3 AC 100% 294ms 161184KB
4 AC 100% 429ms 235440KB
5 AC 100% 319ms 168672KB
6 AC 100% 393ms 231360KB
7 AC 100% 475ms 235776KB
8 AC 100% 464ms 241792KB
9 AC 100% 279ms 165776KB
10 AC 100% 459ms 236240KB
11 AC 100% 330ms 172400KB
12 AC 100% 271ms 149312KB
13 AC 100% 343ms 229776KB
14 AC 100% 455ms 240784KB
15 AC 100% 436ms 237552KB
16 AC 100% 363ms 229184KB
17 AC 100% 492ms 243536KB
18 AC 100% 410ms 232448KB
19 AC 100% 255ms 149504KB
20 AC 100% 339ms 229424KB
21 AC 100% 270ms 151904KB
22 AC 100% 343ms 170768KB
23 AC 100% 338ms 173392KB
24 MLE 0% 490ms 277984KB
25 AC 100% 475ms 240480KB
26 AC 100% 448ms 238096KB
27 AC 100% 301ms 154992KB
28 AC 100% 263ms 144912KB
29 AC 100% 382ms 175792KB
30 AC 100% 351ms 230528KB
31 AC 100% 468ms 236576KB
32 AC 100% 336ms 222576KB
33 AC 100% 297ms 141600KB
34 AC 100% 462ms 239936KB
35 AC 100% 260ms 136992KB
36 AC 100% 325ms 239104KB
37 AC 100% 318ms 165040KB
38 AC 100% 238ms 131856KB
39 AC 100% 509ms 237360KB
40 AC 100% 255ms 146240KB
41 AC 100% 408ms 233920KB
42 AC 100% 270ms 153376KB
43 AC 100% 474ms 238400KB
44 AC 100% 383ms 229968KB
45 AC 100% 413ms 230784KB
46 AC 100% 420ms 230592KB
47 AC 100% 447ms 242736KB
48 AC 100% 441ms 234928KB
49 AC 100% 350ms 184304KB
50 AC 100% 442ms 236544KB
51 AC 100% 270ms 143680KB
52 AC 100% 382ms 171120KB
53 AC 100% 290ms 159008KB
54 AC 100% 388ms 230800KB
55 AC 100% 286ms 151664KB
56 AC 100% 402ms 240912KB
57 AC 100% 353ms 177056KB
58 AC 100% 336ms 168224KB
59 AC 100% 370ms 157600KB
60 AC 100% 283ms 153968KB
61 AC 100% 339ms 167600KB
62 AC 100% 437ms 235232KB
63 AC 100% 481ms 243024KB
64 AC 100% 454ms 241440KB
65 AC 100% 418ms 234512KB
66 AC 100% 178ms 127696KB
67 AC 100% 364ms 233040KB
68 AC 100% 380ms 243616KB
69 MLE 0% 632ms 288832KB
70 AC 100% 426ms 234608KB

ソースコード

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.io.IOException;
import java.io.Reader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.AbstractCollection;
import java.util.List;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyInput in = new MyInput(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        public void solve(int testNumber, MyInput in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int k = in.nextInt();

            Graph g = new Graph(n);
            for (int i = 0; i < m; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                int c = in.nextInt();
                g.addEdge(a, b, c, i);
                g.addEdge(b, a, c, i);
            }

            int[] max = new int[n];
            Arrays.fill(max, -1);
            PriorityQueue<Long> que = new PriorityQueue<>(Comparator.comparingLong(x -> -x));
            for (int i = 0; i < k; i++) {
                int h = in.nextInt() - 1;
                int d = in.nextInt();
                que.add((long) d << 32 | h);
                max[h] = d;
            }
            while (!que.isEmpty()) {
                long x = que.poll();
                int d = (int) (x >>> 32);
                int i = (int) (x & 0xFFFFFFFFL);
                if (max[i] != d) continue;
                for (Edge e : g.vertex[i].edges) {
                    int c = (int) (d - e.cost);
                    if (c <= max[e.to]) continue;
                    max[e.to] = c;
                    que.add((long) c << 32 | e.to);
                }
            }
            out.println(Arrays.stream(max).filter(x -> x >= 0).count());
        }

        class Edge {
            public final int edgeId;
            public final int to;
            public long cost;

            public Edge(int to, long cost, int edgeId) {
                this.to = to;
                this.cost = cost;
                this.edgeId = edgeId;
            }


            public String toString() {
                return String.format("[Edge id=%d, to=%d, cost=%d]", edgeId, to, cost);
            }

        }

        class Vertex {
            public final int id;
            public final List<Edge> edges = new ArrayList<>();

            public Vertex(final int id) {
                this.id = id;
            }

            public void addEdge(Edge e) {
                edges.add(e);
            }

        }

        class Graph {
            int V;
            int E;
            Vertex[] vertex;

            public Graph(int V) {
                this.V = V;
                this.E = 0;
                vertex = new Vertex[V];
                for (int i = 0; i < V; i++) vertex[i] = new Vertex(i);
            }

            public void addEdge(int s, int t, long c, int edgeId) {
                vertex[s].addEdge(new Edge(t, c, edgeId));
            }

        }

    }

    static class MyInput {
        private final BufferedReader in;
        private static int pos;
        private static int readLen;
        private static final char[] buffer = new char[1024 * 8];
        private static char[] str = new char[500 * 8 * 2];
        private static boolean[] isDigit = new boolean[256];
        private static boolean[] isSpace = new boolean[256];
        private static boolean[] isLineSep = new boolean[256];

        static {
            for (int i = 0; i < 10; i++) {
                isDigit['0' + i] = true;
            }
            isDigit['-'] = true;
            isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
            isLineSep['\r'] = isLineSep['\n'] = true;
        }

        public MyInput(InputStream is) {
            in = new BufferedReader(new InputStreamReader(is));
        }

        public int read() {
            if (pos >= readLen) {
                pos = 0;
                try {
                    readLen = in.read(buffer);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (readLen <= 0) {
                    throw new MyInput.EndOfFileRuntimeException();
                }
            }
            return buffer[pos++];
        }

        public int nextInt() {
            int len = 0;
            str[len++] = nextChar();
            len = reads(len, isSpace);
            int i = 0;
            int ret = 0;
            if (str[0] == '-') {
                i = 1;
            }
            for (; i < len; i++) ret = ret * 10 + str[i] - '0';
            if (str[0] == '-') {
                ret = -ret;
            }
            return ret;
        }

        public char nextChar() {
            while (true) {
                final int c = read();
                if (!isSpace[c]) {
                    return (char) c;
                }
            }
        }

        int reads(int len, boolean[] accept) {
            try {
                while (true) {
                    final int c = read();
                    if (accept[c]) {
                        break;
                    }
                    if (str.length == len) {
                        char[] rep = new char[str.length * 3 / 2];
                        System.arraycopy(str, 0, rep, 0, str.length);
                        str = rep;
                    }
                    str[len++] = (char) c;
                }
            } catch (MyInput.EndOfFileRuntimeException e) {
            }
            return len;
        }

        static class EndOfFileRuntimeException extends RuntimeException {
        }

    }
}