# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29130 | 2017-07-18T11:04:58 Z | jjwdi0 | Alternative Mart (FXCUP2_mart) | C++11 | 1743 ms | 61808 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; struct Z { int x, y, c; } T[80003]; struct Q { int x, st; ll c; Q(int _x, int _st, ll _c) { x = _x, st = _st, c = _c; } bool operator < (const Q &A) const { return c == A.c ? st < A.st : c < A.c; } bool operator > (const Q &A) const { return c == A.c ? st > A.st : c > A.c; } }; int N, M, K, _Q; vector<int> v[50003]; bool mart[50003]; ll D[50003][12]; int num[50003][12], idx[50003]; int q[13]; priority_queue<Q, vector<Q>, greater<Q>> pq; int main() { scanf("%d %d %d %d", &N, &M, &K, &_Q); for(int i=0, x; i<K; i++) scanf("%d", &x), mart[x] = 1; for(int i=0; i<M; i++) { scanf("%d %d %d", &T[i].x, &T[i].y, &T[i].c); v[T[i].x].push_back(i); v[T[i].y].push_back(i); } for(int i=1; i<=N; i++) for(int j=1; j<=11; j++) D[i][j] = 1e15; for(int i=1; i<=N; idx[i] = 1, i++) if(mart[i]) pq.push(Q(i, i, 0)); while(!pq.empty()) { int u = pq.top().x, st = pq.top().st; ll cost = pq.top().c; pq.pop(); int id = idx[u]; if(id > 11) continue; bool chk = 0; for(int i=1; i<=id; i++) if(num[u][i] == st) chk = 1; if(chk) continue; num[u][id] = st, idx[u]++, D[u][id] = cost; for(int it : v[u]) { int ne = T[it].x == u ? T[it].y : T[it].x; ll c = T[it].c; pq.push(Q(ne, st, c + cost)); } } for(int i=0; i<_Q; i++) { int s, x; scanf("%d %d", &s, &x); for(int j=0; j<x; j++) scanf("%d", q+j); for(int j=1; j<=11; j++) { bool chk = 0; for(int k=0; k<x; k++) if(q[k] == num[s][j]) chk = 1; if(chk == 0) { printf("%d %lld\n", num[s][j], D[s][j]); break; } } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 11408 KB | Output is correct |
2 | Correct | 0 ms | 11408 KB | Output is correct |
3 | Correct | 0 ms | 11408 KB | Output is correct |
4 | Correct | 0 ms | 11408 KB | Output is correct |
5 | Correct | 0 ms | 11552 KB | Output is correct |
6 | Correct | 0 ms | 11552 KB | Output is correct |
7 | Correct | 3 ms | 11564 KB | Output is correct |
8 | Correct | 3 ms | 11408 KB | Output is correct |
9 | Correct | 99 ms | 17820 KB | Output is correct |
10 | Correct | 63 ms | 17820 KB | Output is correct |
11 | Correct | 36 ms | 12036 KB | Output is correct |
12 | Correct | 23 ms | 11672 KB | Output is correct |
13 | Correct | 1739 ms | 61804 KB | Output is correct |
14 | Correct | 1409 ms | 61808 KB | Output is correct |
15 | Correct | 119 ms | 13492 KB | Output is correct |
16 | Correct | 99 ms | 12992 KB | Output is correct |
17 | Correct | 643 ms | 16180 KB | Output is correct |
18 | Correct | 383 ms | 12992 KB | Output is correct |
19 | Correct | 823 ms | 16184 KB | Output is correct |
20 | Correct | 459 ms | 12992 KB | Output is correct |
21 | Correct | 773 ms | 19256 KB | Output is correct |
22 | Correct | 439 ms | 13436 KB | Output is correct |
23 | Correct | 659 ms | 25396 KB | Output is correct |
24 | Correct | 643 ms | 19200 KB | Output is correct |
25 | Correct | 673 ms | 25400 KB | Output is correct |
26 | Correct | 599 ms | 19200 KB | Output is correct |
27 | Correct | 169 ms | 14696 KB | Output is correct |
28 | Correct | 159 ms | 13828 KB | Output is correct |
29 | Correct | 1186 ms | 19300 KB | Output is correct |
30 | Correct | 753 ms | 16128 KB | Output is correct |
31 | Correct | 1073 ms | 25420 KB | Output is correct |
32 | Correct | 736 ms | 16128 KB | Output is correct |
33 | Correct | 966 ms | 19268 KB | Output is correct |
34 | Correct | 1329 ms | 25396 KB | Output is correct |
35 | Correct | 1179 ms | 25420 KB | Output is correct |
36 | Correct | 1236 ms | 25364 KB | Output is correct |
37 | Correct | 1339 ms | 37768 KB | Output is correct |
38 | Correct | 1283 ms | 37664 KB | Output is correct |
39 | Correct | 153 ms | 14832 KB | Output is correct |
40 | Correct | 166 ms | 14768 KB | Output is correct |
41 | Correct | 1516 ms | 25584 KB | Output is correct |
42 | Correct | 1383 ms | 25524 KB | Output is correct |
43 | Correct | 1436 ms | 37868 KB | Output is correct |
44 | Correct | 1303 ms | 37808 KB | Output is correct |
45 | Correct | 1743 ms | 37876 KB | Output is correct |
46 | Correct | 1319 ms | 37812 KB | Output is correct |
47 | Correct | 1726 ms | 37872 KB | Output is correct |
48 | Correct | 1693 ms | 37808 KB | Output is correct |
49 | Correct | 1053 ms | 37876 KB | Output is correct |
50 | Correct | 1136 ms | 37812 KB | Output is correct |
51 | Correct | 1002 ms | 37872 KB | Output is correct |
52 | Correct | 1113 ms | 37812 KB | Output is correct |
53 | Correct | 276 ms | 12992 KB | Output is correct |
54 | Correct | 1319 ms | 25384 KB | Output is correct |
55 | Correct | 1499 ms | 25456 KB | Output is correct |
56 | Correct | 1296 ms | 37808 KB | Output is correct |
57 | Correct | 1346 ms | 61612 KB | Output is correct |