# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29188 | 2017-07-18T15:25:19 Z | junodeveloper | Alternative Mart (FXCUP2_mart) | C++14 | 2306 ms | 68580 KB |
#include<cstdio> #include<iostream> #include<vector> #include<queue> #include<set> using namespace std; typedef long long ll; int n, m, k, q; int martIdx[50001]; set<int> visited[50001]; vector<pair<ll,int> > dist[50001]; vector<pair<int,ll> > adj[50001]; void dijkstra() { priority_queue<pair<ll, pair<int, int> > > q; for(int i = 0; i < k; ++i) q.push({0, {-martIdx[i], martIdx[i]}}); while(!q.empty()) { int u = q.top().second.second; int from = -q.top().second.first; ll c = -q.top().first; q.pop(); if(visited[u].size() == 11 || visited[u].find(from) != visited[u].end()) continue; visited[u].insert(from); dist[u].push_back({c, from}); for(auto& t : adj[u]) { int to = t.first; ll cost = t.second; q.push({-(c + cost), {-from, to}}); } } } int main() { scanf("%d%d%d%d", &n, &m, &k, &q); for(int i = 0; i < k; ++i) scanf("%d", martIdx + i); for(int i = 0; i < m; ++i) { int a, b, v; scanf("%d%d%d", &a, &b, &v); adj[a].push_back({b, v}); adj[b].push_back({a, v}); } dijkstra(); for(int i = 0; i < q; ++i) { int s, x; scanf("%d%d", &s, &x); ll mn = 1e18, rIdx = 1e18; bool closed[11] = {0}; for(int j = 0, idx; j < x; ++j) { scanf("%d", &idx); for(int l = 0; l < dist[s].size(); ++l) if(dist[s][l].second == idx) closed[l] = 1; } for(int j = 0; j < dist[s].size(); ++j) { if(closed[j]) continue; if(dist[s][j].first < mn || (dist[s][j].first == mn && dist[s][j].second < rIdx)) { mn = dist[s][j].first; rIdx = dist[s][j].second; } } printf("%lld %lld\n", rIdx, mn); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 6908 KB | Output is correct |
2 | Correct | 3 ms | 6908 KB | Output is correct |
3 | Correct | 0 ms | 6908 KB | Output is correct |
4 | Correct | 0 ms | 6908 KB | Output is correct |
5 | Correct | 0 ms | 7056 KB | Output is correct |
6 | Correct | 0 ms | 7056 KB | Output is correct |
7 | Correct | 6 ms | 7436 KB | Output is correct |
8 | Correct | 3 ms | 7304 KB | Output is correct |
9 | Correct | 93 ms | 13844 KB | Output is correct |
10 | Correct | 76 ms | 13832 KB | Output is correct |
11 | Correct | 96 ms | 11396 KB | Output is correct |
12 | Correct | 43 ms | 11136 KB | Output is correct |
13 | Correct | 799 ms | 62280 KB | Output is correct |
14 | Correct | 973 ms | 62300 KB | Output is correct |
15 | Correct | 159 ms | 13652 KB | Output is correct |
16 | Correct | 106 ms | 13244 KB | Output is correct |
17 | Correct | 1309 ms | 48692 KB | Output is correct |
18 | Correct | 823 ms | 47300 KB | Output is correct |
19 | Correct | 1253 ms | 51200 KB | Output is correct |
20 | Correct | 1103 ms | 49544 KB | Output is correct |
21 | Correct | 1419 ms | 53380 KB | Output is correct |
22 | Correct | 1223 ms | 49728 KB | Output is correct |
23 | Correct | 1219 ms | 58272 KB | Output is correct |
24 | Correct | 1326 ms | 54356 KB | Output is correct |
25 | Correct | 1216 ms | 58668 KB | Output is correct |
26 | Correct | 1506 ms | 54876 KB | Output is correct |
27 | Correct | 183 ms | 15104 KB | Output is correct |
28 | Correct | 156 ms | 14288 KB | Output is correct |
29 | Correct | 1899 ms | 51676 KB | Output is correct |
30 | Correct | 1536 ms | 49352 KB | Output is correct |
31 | Correct | 1363 ms | 57768 KB | Output is correct |
32 | Correct | 1443 ms | 51468 KB | Output is correct |
33 | Correct | 1376 ms | 53524 KB | Output is correct |
34 | Correct | 1669 ms | 58396 KB | Output is correct |
35 | Correct | 1416 ms | 58608 KB | Output is correct |
36 | Correct | 1673 ms | 58964 KB | Output is correct |
37 | Correct | 1753 ms | 67820 KB | Output is correct |
38 | Correct | 1559 ms | 67644 KB | Output is correct |
39 | Correct | 179 ms | 15740 KB | Output is correct |
40 | Correct | 226 ms | 15780 KB | Output is correct |
41 | Correct | 2306 ms | 56424 KB | Output is correct |
42 | Correct | 1796 ms | 56600 KB | Output is correct |
43 | Correct | 1919 ms | 66860 KB | Output is correct |
44 | Correct | 1939 ms | 67024 KB | Output is correct |
45 | Correct | 1443 ms | 66868 KB | Output is correct |
46 | Correct | 1689 ms | 66992 KB | Output is correct |
47 | Correct | 1823 ms | 67784 KB | Output is correct |
48 | Correct | 1896 ms | 67660 KB | Output is correct |
49 | Correct | 1899 ms | 68180 KB | Output is correct |
50 | Correct | 1916 ms | 68188 KB | Output is correct |
51 | Correct | 1496 ms | 68444 KB | Output is correct |
52 | Correct | 1399 ms | 68580 KB | Output is correct |
53 | Correct | 483 ms | 48628 KB | Output is correct |
54 | Correct | 1703 ms | 57912 KB | Output is correct |
55 | Correct | 1603 ms | 57980 KB | Output is correct |
56 | Correct | 1959 ms | 66744 KB | Output is correct |
57 | Correct | 916 ms | 60844 KB | Output is correct |