# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
28464 | 2017-07-16T06:14:55 Z | not good but never sad(#1132, kriii) | Alternative Mart (FXCUP2_mart) | C++14 | 4403 ms | 51040 KB |
#include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> using namespace std; struct phase{ int s,x,c; bool operator <(const phase &t) const{return c > t.c;} }; priority_queue<phase> Q; map<int, int> dist[50505]; vector<pair<int, int> > G[50505]; int N,M,K,q; pair<int, int> mx(map<int, int> &m) { pair<int, int> ret; for (auto &p : m){ ret = max(ret,{p.second,p.first}); } return ret; } int main() { scanf ("%d %d %d %d",&N,&M,&K,&q); for (int i=0;i<K;i++){ int x; scanf ("%d",&x); dist[x][x] = 0; Q.push({x,x,0}); } for (int i=0;i<M;i++){ int x,y,c; scanf ("%d %d %d",&x,&y,&c); G[x].push_back({y,c}); G[y].push_back({x,c}); } while (!Q.empty()){ int s = Q.top().s, x = Q.top().x, c = Q.top().c; Q.pop(); if (!dist[x].count(s) || dist[x][s] != c) continue; for (auto &p : G[x]){ int y = p.first; int nc = c + p.second; if (dist[y].count(s) && dist[y][s] <= nc) continue; if (dist[y].size() < 12 || mx(dist[y]) > make_pair(nc,s)){ dist[y][s] = nc; if (dist[y].size() == 12){ auto p = mx(dist[y]); dist[y].erase(p.second); } Q.push({s,y,nc}); } } } while (q--){ int x,n; set<int> chk; scanf ("%d %d",&x,&n); while (n--){ int t; scanf ("%d",&t); chk.insert(t); } vector<pair<int, int> > u; for (auto &p : dist[x]){ u.push_back({p.second,p.first}); } sort(u.begin(),u.end()); for (auto &p : u){ if(!chk.count(p.second)){ printf ("%d %d\n",p.second,p.first); break; } } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4732 KB | Output is correct |
2 | Correct | 0 ms | 4732 KB | Output is correct |
3 | Correct | 3 ms | 4732 KB | Output is correct |
4 | Correct | 0 ms | 4732 KB | Output is correct |
5 | Correct | 0 ms | 4732 KB | Output is correct |
6 | Correct | 3 ms | 4732 KB | Output is correct |
7 | Correct | 3 ms | 4996 KB | Output is correct |
8 | Correct | 6 ms | 4996 KB | Output is correct |
9 | Correct | 176 ms | 10024 KB | Output is correct |
10 | Correct | 16 ms | 5540 KB | Output is correct |
11 | Correct | 56 ms | 7672 KB | Output is correct |
12 | Correct | 43 ms | 7504 KB | Output is correct |
13 | Correct | 2799 ms | 46116 KB | Output is correct |
14 | Correct | 3036 ms | 46124 KB | Output is correct |
15 | Correct | 96 ms | 9028 KB | Output is correct |
16 | Correct | 66 ms | 8692 KB | Output is correct |
17 | Correct | 1089 ms | 30852 KB | Output is correct |
18 | Correct | 769 ms | 29812 KB | Output is correct |
19 | Correct | 686 ms | 33992 KB | Output is correct |
20 | Correct | 673 ms | 32056 KB | Output is correct |
21 | Correct | 909 ms | 33992 KB | Output is correct |
22 | Correct | 1053 ms | 32132 KB | Output is correct |
23 | Correct | 1729 ms | 35412 KB | Output is correct |
24 | Correct | 1683 ms | 33612 KB | Output is correct |
25 | Correct | 1506 ms | 35412 KB | Output is correct |
26 | Correct | 1766 ms | 33612 KB | Output is correct |
27 | Correct | 126 ms | 9524 KB | Output is correct |
28 | Correct | 129 ms | 9236 KB | Output is correct |
29 | Correct | 1409 ms | 31968 KB | Output is correct |
30 | Correct | 1196 ms | 30780 KB | Output is correct |
31 | Correct | 2153 ms | 35596 KB | Output is correct |
32 | Correct | 1116 ms | 33012 KB | Output is correct |
33 | Correct | 1733 ms | 35576 KB | Output is correct |
34 | Correct | 2609 ms | 38996 KB | Output is correct |
35 | Correct | 2266 ms | 38748 KB | Output is correct |
36 | Correct | 2883 ms | 38880 KB | Output is correct |
37 | Correct | 3269 ms | 39012 KB | Output is correct |
38 | Correct | 3316 ms | 38880 KB | Output is correct |
39 | Correct | 146 ms | 10048 KB | Output is correct |
40 | Correct | 143 ms | 10076 KB | Output is correct |
41 | Correct | 1599 ms | 33852 KB | Output is correct |
42 | Correct | 1723 ms | 33884 KB | Output is correct |
43 | Correct | 3636 ms | 39300 KB | Output is correct |
44 | Correct | 3989 ms | 39196 KB | Output is correct |
45 | Correct | 4003 ms | 39260 KB | Output is correct |
46 | Correct | 4403 ms | 39260 KB | Output is correct |
47 | Correct | 4026 ms | 48136 KB | Output is correct |
48 | Correct | 3769 ms | 49852 KB | Output is correct |
49 | Correct | 3916 ms | 48004 KB | Output is correct |
50 | Correct | 3256 ms | 49588 KB | Output is correct |
51 | Correct | 3493 ms | 49588 KB | Output is correct |
52 | Correct | 3363 ms | 51040 KB | Output is correct |
53 | Correct | 499 ms | 32056 KB | Output is correct |
54 | Correct | 2466 ms | 35852 KB | Output is correct |
55 | Correct | 2753 ms | 38932 KB | Output is correct |
56 | Correct | 3266 ms | 39272 KB | Output is correct |
57 | Correct | 733 ms | 17140 KB | Output is correct |