# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
205775 | 2020-02-29T20:43:12 Z | ly20 | Toll (BOI17_toll) | C++17 | 136 ms | 31480 KB |
#include <bits/stdc++.h> using namespace std; const int MAXN = 512345; const long long INF = 1123456789012; long long v[MAXN]; vector <int> grafo[MAXN]; vector <long long> peso[MAXN]; long long dist[MAXN]; int grau[MAXN]; int main() { int k, n, m, o; scanf("%d %d %d %d", &k, &n, &m, &o); for(int i = 0; i < m; i++) { int a, b; long long p; scanf("%d %d", &a, &b); grau[b]++; scanf("%lld", &p); grafo[a].push_back(b); peso[a].push_back(p); } for(int i = 0; i < n; i++) dist[i] = INF; dist[0] = 0LL; queue <int> fila; for(int i = 0; i < n; i++) if(grau[i] == 0) fila.push(i); while(!fila.empty()) { int cur = fila.front(); fila.pop(); for(int i = 0; i < grafo[cur].size(); i++) { int viz = grafo[cur][i]; long long p = peso[cur][i]; dist[viz] = min(dist[viz], dist[cur] + p); grau[viz]--; if(grau[viz] == 0) fila.push(viz); } } for(int i = 0; i < o; i++) { int a, b; scanf("%d %d", &a, &b); if(dist[b] >= INF) printf("-1\n"); else printf("%lld\n", dist[b]); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 63 ms | 28152 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 100 ms | 28152 KB | Output is correct |
2 | Correct | 21 ms | 24440 KB | Output is correct |
3 | Correct | 21 ms | 24440 KB | Output is correct |
4 | Correct | 20 ms | 24440 KB | Output is correct |
5 | Correct | 20 ms | 24444 KB | Output is correct |
6 | Correct | 20 ms | 24440 KB | Output is correct |
7 | Correct | 25 ms | 24568 KB | Output is correct |
8 | Correct | 26 ms | 24572 KB | Output is correct |
9 | Correct | 63 ms | 29048 KB | Output is correct |
10 | Correct | 129 ms | 31480 KB | Output is correct |
11 | Correct | 105 ms | 30072 KB | Output is correct |
12 | Correct | 91 ms | 29176 KB | Output is correct |
13 | Correct | 136 ms | 31352 KB | Output is correct |
14 | Correct | 84 ms | 29084 KB | Output is correct |
15 | Correct | 78 ms | 28152 KB | Output is correct |
16 | Correct | 78 ms | 28408 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 24440 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 24440 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 63 ms | 28152 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |