| 提出番号 | 2006 |
|---|---|
| 提出者 | tanzaku |
| 言語 | Java |
| 提出日時 | 2018-08-04 14:53:30 |
| 問題名 | (73)観光計画 |
| 結果 | AC |
| 点数 | 100% |
| テストケース | 結果 | 得点 | 実行時間 | メモリ使用量 |
|---|---|---|---|---|
| 1 | AC | 100% | 342ms | 163616KB |
| 2 | AC | 100% | 394ms | 172992KB |
| 3 | AC | 100% | 301ms | 155808KB |
| 4 | AC | 100% | 391ms | 225040KB |
| 5 | AC | 100% | 301ms | 162352KB |
| 6 | AC | 100% | 423ms | 218064KB |
| 7 | AC | 100% | 459ms | 238752KB |
| 8 | AC | 100% | 481ms | 237680KB |
| 9 | AC | 100% | 294ms | 157456KB |
| 10 | AC | 100% | 441ms | 234608KB |
| 11 | AC | 100% | 318ms | 162752KB |
| 12 | AC | 100% | 270ms | 143680KB |
| 13 | AC | 100% | 339ms | 169312KB |
| 14 | AC | 100% | 420ms | 235888KB |
| 15 | AC | 100% | 435ms | 233584KB |
| 16 | AC | 100% | 367ms | 218416KB |
| 17 | AC | 100% | 432ms | 234240KB |
| 18 | AC | 100% | 379ms | 174368KB |
| 19 | AC | 100% | 295ms | 145168KB |
| 20 | AC | 100% | 325ms | 171584KB |
| 21 | AC | 100% | 247ms | 144656KB |
| 22 | AC | 100% | 339ms | 160384KB |
| 23 | AC | 100% | 344ms | 164384KB |
| 24 | AC | 100% | 441ms | 241536KB |
| 25 | AC | 100% | 458ms | 232736KB |
| 26 | AC | 100% | 437ms | 232768KB |
| 27 | AC | 100% | 281ms | 149072KB |
| 28 | AC | 100% | 243ms | 141120KB |
| 29 | AC | 100% | 379ms | 168640KB |
| 30 | AC | 100% | 351ms | 172304KB |
| 31 | AC | 100% | 516ms | 242768KB |
| 32 | AC | 100% | 336ms | 172688KB |
| 33 | AC | 100% | 275ms | 136800KB |
| 34 | AC | 100% | 448ms | 232864KB |
| 35 | AC | 100% | 260ms | 135760KB |
| 36 | AC | 100% | 302ms | 232048KB |
| 37 | AC | 100% | 333ms | 156064KB |
| 38 | AC | 100% | 237ms | 129680KB |
| 39 | AC | 100% | 457ms | 240368KB |
| 40 | AC | 100% | 226ms | 140016KB |
| 41 | AC | 100% | 536ms | 232816KB |
| 42 | AC | 100% | 311ms | 151696KB |
| 43 | AC | 100% | 493ms | 239040KB |
| 44 | AC | 100% | 350ms | 172192KB |
| 45 | AC | 100% | 398ms | 229792KB |
| 46 | AC | 100% | 359ms | 178592KB |
| 47 | AC | 100% | 465ms | 236688KB |
| 48 | AC | 100% | 375ms | 232304KB |
| 49 | AC | 100% | 355ms | 169248KB |
| 50 | AC | 100% | 388ms | 230880KB |
| 51 | AC | 100% | 256ms | 138992KB |
| 52 | AC | 100% | 357ms | 162880KB |
| 53 | AC | 100% | 314ms | 152720KB |
| 54 | AC | 100% | 340ms | 220096KB |
| 55 | AC | 100% | 284ms | 145008KB |
| 56 | AC | 100% | 332ms | 226288KB |
| 57 | AC | 100% | 336ms | 166032KB |
| 58 | AC | 100% | 357ms | 160560KB |
| 59 | AC | 100% | 313ms | 151376KB |
| 60 | AC | 100% | 286ms | 151744KB |
| 61 | AC | 100% | 318ms | 160512KB |
| 62 | AC | 100% | 392ms | 227168KB |
| 63 | AC | 100% | 421ms | 235264KB |
| 64 | AC | 100% | 450ms | 232304KB |
| 65 | AC | 100% | 413ms | 232736KB |
| 66 | AC | 100% | 200ms | 123744KB |
| 67 | AC | 100% | 388ms | 175232KB |
| 68 | AC | 100% | 352ms | 228736KB |
| 69 | AC | 100% | 553ms | 246208KB |
| 70 | AC | 100% | 419ms | 173280KB |
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.List;
import java.util.AbstractCollection;
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();
List<int[]>[] g = new ArrayList[n];
for (int i = 0; i < n; i++) g[i] = new ArrayList<>();
for (int i = 0; i < m; i++) {
int a = in.nextInt() - 1;
int b = in.nextInt() - 1;
int c = in.nextInt();
g[a].add(new int[]{b, c});
g[b].add(new int[]{a, c});
}
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 (int[] e : g[i]) {
int c = (int) (d - e[1]);
if (c <= max[e[0]]) continue;
max[e[0]] = c;
que.add((long) c << 32 | e[0]);
}
}
out.println(Arrays.stream(max).filter(x -> x >= 0).count());
}
}
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 {
}
}
}