# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28524 | 2017-07-16T06:58:41 Z | 三( ε:)(#1146, xdoju, veckal, unused) | Alternative Mart (FXCUP2_mart) | C++14 | 3759 ms | 50648 KB |
#include <cstdio> #include <vector> #include <queue> #include <set> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef pair<ll, int> li; typedef pair<ll, ii> lii; int main() { //freopen("input.txt", "r", stdin); int n, m, k, q; scanf("%d%d%d%d", &n, &m, &k, &q); vector<set<li>> dist(n); // (distance, from) vector<vector<ii>> adj(n); // (destination, weight) priority_queue<lii> pq; // (-distance, (here, -from)) while (k--) { int s; scanf("%d", &s); --s; dist[s].emplace(0ll, s); pq.emplace(0ll, ii(s, -s)); } while (m--) { int p, q, v; scanf("%d%d%d", &p, &q, &v); --p; --q; adj[p].emplace_back(q, v); adj[q].emplace_back(p, v); } while (!pq.empty()) { ll weight = -pq.top().first; int here = pq.top().second.first; int from = -pq.top().second.second; pq.pop(); bool skip = false; bool hasFrom = false; for (li p : dist[here]) { if (p.second != from) continue; hasFrom = true; if (weight > p.first) skip = true; break; } if (skip || !hasFrom) continue; for (ii p : adj[here]) { int next = p.first; ll nweight = weight + p.second; bool skip = false; bool hasFrom = false; for (auto it = dist[next].begin(); it != dist[next].end(); ++it) { if (it->second != from) continue; hasFrom = true; if (it->first <= nweight) skip = true; else dist[next].erase(it); break; } if (!hasFrom && dist[next].size() >= 11) { int f = dist[next].rbegin()->second; ll d = dist[next].rbegin()->first; if (d < nweight || (d == nweight && f < from)) skip = true; else dist[next].erase(--dist[next].end()); } if (skip) continue; dist[next].emplace(nweight, from); pq.emplace(-nweight, ii(next, -from)); } } while (q--) { int target, x; scanf("%d%d", &target, &x); --target; set<int> closed; while (x--) { int c; scanf("%d", &c); closed.insert(--c); } for (li p : dist[target]) { if (closed.find(p.second) == closed.end()) { printf("%d %lld\n", p.second + 1, p.first); break; } } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 1940 KB | Output is correct |
2 | Correct | 0 ms | 1940 KB | Output is correct |
3 | Correct | 0 ms | 1940 KB | Output is correct |
4 | Correct | 0 ms | 1940 KB | Output is correct |
5 | Correct | 0 ms | 2072 KB | Output is correct |
6 | Correct | 0 ms | 2072 KB | Output is correct |
7 | Correct | 3 ms | 2336 KB | Output is correct |
8 | Correct | 3 ms | 2336 KB | Output is correct |
9 | Correct | 69 ms | 2992 KB | Output is correct |
10 | Correct | 19 ms | 2908 KB | Output is correct |
11 | Correct | 63 ms | 6084 KB | Output is correct |
12 | Correct | 53 ms | 5932 KB | Output is correct |
13 | Correct | 839 ms | 13800 KB | Output is correct |
14 | Correct | 789 ms | 13848 KB | Output is correct |
15 | Correct | 119 ms | 10636 KB | Output is correct |
16 | Correct | 99 ms | 10208 KB | Output is correct |
17 | Correct | 1306 ms | 39568 KB | Output is correct |
18 | Correct | 853 ms | 38324 KB | Output is correct |
19 | Correct | 1349 ms | 43736 KB | Output is correct |
20 | Correct | 1153 ms | 41360 KB | Output is correct |
21 | Correct | 1993 ms | 43712 KB | Output is correct |
22 | Correct | 1849 ms | 41528 KB | Output is correct |
23 | Correct | 2033 ms | 45760 KB | Output is correct |
24 | Correct | 2306 ms | 43448 KB | Output is correct |
25 | Correct | 1999 ms | 45760 KB | Output is correct |
26 | Correct | 1796 ms | 43448 KB | Output is correct |
27 | Correct | 86 ms | 10996 KB | Output is correct |
28 | Correct | 83 ms | 10764 KB | Output is correct |
29 | Correct | 1926 ms | 40904 KB | Output is correct |
30 | Correct | 1626 ms | 39536 KB | Output is correct |
31 | Correct | 2366 ms | 46032 KB | Output is correct |
32 | Correct | 2053 ms | 42652 KB | Output is correct |
33 | Correct | 2136 ms | 43844 KB | Output is correct |
34 | Correct | 3156 ms | 46288 KB | Output is correct |
35 | Correct | 2456 ms | 46024 KB | Output is correct |
36 | Correct | 2483 ms | 46156 KB | Output is correct |
37 | Correct | 2936 ms | 50384 KB | Output is correct |
38 | Correct | 2889 ms | 46156 KB | Output is correct |
39 | Correct | 176 ms | 11680 KB | Output is correct |
40 | Correct | 173 ms | 11696 KB | Output is correct |
41 | Correct | 2376 ms | 43372 KB | Output is correct |
42 | Correct | 2256 ms | 43396 KB | Output is correct |
43 | Correct | 3153 ms | 46540 KB | Output is correct |
44 | Correct | 3123 ms | 46556 KB | Output is correct |
45 | Correct | 3409 ms | 46552 KB | Output is correct |
46 | Correct | 2776 ms | 46552 KB | Output is correct |
47 | Correct | 3169 ms | 50648 KB | Output is correct |
48 | Correct | 3099 ms | 50648 KB | Output is correct |
49 | Correct | 3546 ms | 50648 KB | Output is correct |
50 | Correct | 3759 ms | 50648 KB | Output is correct |
51 | Correct | 1396 ms | 50648 KB | Output is correct |
52 | Correct | 1636 ms | 50648 KB | Output is correct |
53 | Correct | 446 ms | 41492 KB | Output is correct |
54 | Correct | 2626 ms | 46264 KB | Output is correct |
55 | Correct | 2609 ms | 46252 KB | Output is correct |
56 | Correct | 2503 ms | 46516 KB | Output is correct |
57 | Correct | 529 ms | 9012 KB | Output is correct |