답안 #28785

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28785 2017-07-17T07:44:49 Z kriii Alternative Mart (FXCUP2_mart) C++14
1 / 1
4473 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

mart.cpp: In function 'int main()':
mart.cpp:30:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d %d %d %d",&N,&M,&K,&q);
                                   ^
mart.cpp:32:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x; scanf ("%d",&x);
                         ^
mart.cpp:39:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d %d %d",&x,&y,&c);
                              ^
mart.cpp:65:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d %d",&x,&n); while (n--){
                        ^
mart.cpp:66:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int t; scanf ("%d",&t); chk.insert(t);
                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4732 KB Output is correct
2 Correct 0 ms 4732 KB Output is correct
3 Correct 0 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 186 ms 10024 KB Output is correct
10 Correct 13 ms 5540 KB Output is correct
11 Correct 56 ms 7672 KB Output is correct
12 Correct 39 ms 7504 KB Output is correct
13 Correct 2126 ms 46116 KB Output is correct
14 Correct 2076 ms 46124 KB Output is correct
15 Correct 133 ms 9028 KB Output is correct
16 Correct 106 ms 8692 KB Output is correct
17 Correct 723 ms 30852 KB Output is correct
18 Correct 749 ms 29812 KB Output is correct
19 Correct 976 ms 33992 KB Output is correct
20 Correct 906 ms 32056 KB Output is correct
21 Correct 1516 ms 33992 KB Output is correct
22 Correct 1306 ms 32132 KB Output is correct
23 Correct 1613 ms 35412 KB Output is correct
24 Correct 1766 ms 33612 KB Output is correct
25 Correct 1853 ms 35412 KB Output is correct
26 Correct 1616 ms 33612 KB Output is correct
27 Correct 139 ms 9524 KB Output is correct
28 Correct 129 ms 9236 KB Output is correct
29 Correct 1366 ms 31968 KB Output is correct
30 Correct 896 ms 30780 KB Output is correct
31 Correct 1296 ms 35596 KB Output is correct
32 Correct 1113 ms 33012 KB Output is correct
33 Correct 1953 ms 35576 KB Output is correct
34 Correct 3336 ms 38996 KB Output is correct
35 Correct 2386 ms 38748 KB Output is correct
36 Correct 3089 ms 38880 KB Output is correct
37 Correct 3506 ms 39012 KB Output is correct
38 Correct 3473 ms 38880 KB Output is correct
39 Correct 143 ms 10048 KB Output is correct
40 Correct 163 ms 10076 KB Output is correct
41 Correct 1709 ms 33852 KB Output is correct
42 Correct 1183 ms 33884 KB Output is correct
43 Correct 3939 ms 39300 KB Output is correct
44 Correct 3719 ms 39196 KB Output is correct
45 Correct 4053 ms 39260 KB Output is correct
46 Correct 4113 ms 39260 KB Output is correct
47 Correct 4253 ms 48136 KB Output is correct
48 Correct 4179 ms 49852 KB Output is correct
49 Correct 4473 ms 48004 KB Output is correct
50 Correct 3729 ms 49588 KB Output is correct
51 Correct 3316 ms 49588 KB Output is correct
52 Correct 3106 ms 51040 KB Output is correct
53 Correct 593 ms 32056 KB Output is correct
54 Correct 2346 ms 35852 KB Output is correct
55 Correct 1806 ms 38932 KB Output is correct
56 Correct 2386 ms 39272 KB Output is correct
57 Correct 576 ms 17140 KB Output is correct