# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
28484 | 2017-07-16T06:31:01 Z | 三( ε:)(#1146, xdoju, veckal, unused) | Alternative Mart (FXCUP2_mart) | C++14 | 1856 ms | 36320 KB |
#include <cstdio> #include <vector> #include <queue> #include <set> using namespace std; typedef pair<int, int> ii; typedef pair<int, ii> iii; int main() { //freopen("input.txt", "r", stdin); int n, m, k, q; scanf("%d%d%d%d", &n, &m, &k, &q); vector<set<ii>> dist(n); // (distance, from) vector<vector<ii>> adj(n); // (destination, weight) priority_queue<iii> pq; // (-distance, (here, from)) while (k--) { int s; scanf("%d", &s); --s; dist[s].emplace(0, s); pq.emplace(0, 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()) { int 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 (ii 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; int 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) { if (dist[next].rbegin()->first <= nweight) 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 (ii p : dist[target]) { if (closed.find(p.second) == closed.end()) { printf("%d %d\n", p.second + 1, p.first); break; } } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | 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 | 1940 KB | Output is correct |
6 | Correct | 0 ms | 1940 KB | Output is correct |
7 | Correct | 3 ms | 2336 KB | Output is correct |
8 | Correct | 3 ms | 2204 KB | Output is correct |
9 | Correct | 63 ms | 2848 KB | Output is correct |
10 | Correct | 16 ms | 2664 KB | Output is correct |
11 | Correct | 56 ms | 5140 KB | Output is correct |
12 | Correct | 53 ms | 5008 KB | Output is correct |
13 | Correct | 816 ms | 11380 KB | Output is correct |
14 | Correct | 956 ms | 11428 KB | Output is correct |
15 | Correct | 133 ms | 9752 KB | Output is correct |
16 | Correct | 116 ms | 9416 KB | Output is correct |
17 | Correct | 1409 ms | 31576 KB | Output is correct |
18 | Correct | 843 ms | 30536 KB | Output is correct |
19 | Correct | 1646 ms | 34716 KB | Output is correct |
20 | Correct | 1166 ms | 32780 KB | Output is correct |
21 | Correct | 1856 ms | 34716 KB | Output is correct |
22 | Correct | 1646 ms | 32856 KB | Output is correct |
23 | Correct | 1676 ms | 36136 KB | Output is correct |
24 | Correct | 1856 ms | 34336 KB | Output is correct |
25 | Correct | 1219 ms | 36136 KB | Output is correct |
26 | Correct | 1276 ms | 34336 KB | Output is correct |
27 | Correct | 129 ms | 10248 KB | Output is correct |
28 | Correct | 133 ms | 9960 KB | Output is correct |
29 | Correct | 1726 ms | 32692 KB | Output is correct |
30 | Correct | 1769 ms | 31504 KB | Output is correct |
31 | Incorrect | 1809 ms | 36320 KB | Output isn't correct |
32 | Halted | 0 ms | 0 KB | - |