Submission #28581

# Submission time Handle Problem Language Result Execution time Memory
28581 2017-07-16T07:38:03 Z 뚜룹뚜룹뚜룹뚜스~><(#1151, chan492811) Alternative Mart (FXCUP2_mart) C++
1 / 1
2126 ms 55256 KB
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#define K 14
using namespace std;

struct data{ int from, to, d; };
struct cmp{
	bool operator()(data d1, data d2){ if(d1.d == d2.d) return d1.from > d2.from; return d1.d > d2.d; }
};
int n, m, k, q;
int iarr[50010], arr[20];
data darr[50010][20];
vector <data> vt[50010];
priority_queue <data, vector<data>, cmp> pq;

bool compare(data d1, data d2){
	if(d1.d == d2.d) return d1.from < d2.from;
	return d1.d < d2.d;
}
void dijkstra(){
	int i, j, idx, a, d, s, nd, flag;
	data tmp;
	while(!pq.empty()){
		tmp = pq.top(); pq.pop();
		a = tmp.to; d = tmp.d; idx = tmp.from; flag = 0;
		if(iarr[a] >= K) continue;
		for(i = 0; i < iarr[a]; i++){
			if(darr[a][i].from == idx) flag = 1;
		}
		if(flag) continue;
		darr[a][iarr[a]++] = (data){idx, a, d};
		for(i = 0; i < vt[a].size(); i++){
			s = vt[a][i].to;
			/*flag = 0;
			for(j = 0; j < iarr[s]; j++) if(darr[s][i].from == idx) flag = 1;
			if(flag) continue;
			*/pq.push((data){idx, s, d + vt[a][i].d});
		}
	}
}
int main(){
	int i, j, l, a, s, d, flag;
	scanf("%d %d %d %d", &n, &m, &k, &q);
	for(i = 0; i < k; i++){
		scanf("%d", &a);
		pq.push((data){a, a, 0});
	}
	for(i = 0; i < m; i++){
		scanf("%d %d %d", &a, &s, &d);
		vt[a].push_back((data){a, s, d});
		vt[s].push_back((data){s, a, d});
	}
	dijkstra();
	for(i = 1; i <= n; i++){
		sort(darr[i], darr[i] + iarr[i], compare);
	}
	for(i = 0; i < q; i++){
		scanf("%d %d", &a, &s);
		for(j = 0; j < s; j++) scanf("%d", &arr[j]);
		for(j = 0; j < iarr[a]; j++){
			flag = 0;
			for(l = 0; l < s; l++){
				if(arr[l] == darr[a][j].from) flag = 1;
			}
			if(!flag){ printf("%d %d\n", darr[a][j].from, darr[a][j].d); break;}
		}
	}
	return 0;
}

Compilation message

mart.cpp: In function 'void dijkstra()':
mart.cpp:34:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(i = 0; i < vt[a].size(); i++){
                ^
mart.cpp:23:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j, idx, a, d, s, nd, flag;
         ^
mart.cpp:23:26: warning: unused variable 'nd' [-Wunused-variable]
  int i, j, idx, a, d, s, nd, flag;
                          ^
mart.cpp: In function 'int main()':
mart.cpp:45:38: 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:47:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a);
                  ^
mart.cpp:51:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &a, &s, &d);
                                ^
mart.cpp:60:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &s);
                         ^
mart.cpp:61:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(j = 0; j < s; j++) scanf("%d", &arr[j]);
                                              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 15024 KB Output is correct
2 Correct 0 ms 15024 KB Output is correct
3 Correct 0 ms 15024 KB Output is correct
4 Correct 0 ms 15024 KB Output is correct
5 Correct 0 ms 15156 KB Output is correct
6 Correct 0 ms 15156 KB Output is correct
7 Correct 3 ms 15168 KB Output is correct
8 Correct 3 ms 15024 KB Output is correct
9 Correct 129 ms 24764 KB Output is correct
10 Correct 46 ms 20148 KB Output is correct
11 Correct 36 ms 15896 KB Output is correct
12 Correct 26 ms 15156 KB Output is correct
13 Correct 1763 ms 55244 KB Output is correct
14 Correct 1739 ms 55256 KB Output is correct
15 Correct 109 ms 17608 KB Output is correct
16 Correct 83 ms 16608 KB Output is correct
17 Correct 556 ms 19532 KB Output is correct
18 Correct 209 ms 16608 KB Output is correct
19 Correct 846 ms 21840 KB Output is correct
20 Correct 466 ms 16608 KB Output is correct
21 Correct 926 ms 21884 KB Output is correct
22 Correct 623 ms 17004 KB Output is correct
23 Correct 943 ms 26436 KB Output is correct
24 Correct 833 ms 21168 KB Output is correct
25 Correct 996 ms 26436 KB Output is correct
26 Correct 1029 ms 21168 KB Output is correct
27 Correct 129 ms 18908 KB Output is correct
28 Correct 119 ms 17948 KB Output is correct
29 Correct 1026 ms 22344 KB Output is correct
30 Correct 713 ms 19412 KB Output is correct
31 Correct 1226 ms 26712 KB Output is correct
32 Correct 763 ms 19240 KB Output is correct
33 Correct 1196 ms 26632 KB Output is correct
34 Correct 1243 ms 36388 KB Output is correct
35 Correct 1323 ms 26700 KB Output is correct
36 Correct 1509 ms 36048 KB Output is correct
37 Correct 1819 ms 36312 KB Output is correct
38 Correct 1589 ms 36180 KB Output is correct
39 Correct 169 ms 19480 KB Output is correct
40 Correct 153 ms 19480 KB Output is correct
41 Correct 1506 ms 27540 KB Output is correct
42 Correct 1416 ms 27544 KB Output is correct
43 Correct 1889 ms 36756 KB Output is correct
44 Correct 1809 ms 36760 KB Output is correct
45 Correct 1989 ms 36804 KB Output is correct
46 Correct 1846 ms 36804 KB Output is correct
47 Correct 1933 ms 36708 KB Output is correct
48 Correct 1923 ms 36708 KB Output is correct
49 Correct 2076 ms 36708 KB Output is correct
50 Correct 2126 ms 36708 KB Output is correct
51 Correct 1096 ms 55140 KB Output is correct
52 Correct 1063 ms 55140 KB Output is correct
53 Correct 316 ms 16608 KB Output is correct
54 Correct 1566 ms 27020 KB Output is correct
55 Correct 1609 ms 36272 KB Output is correct
56 Correct 2089 ms 36780 KB Output is correct
57 Correct 1963 ms 54736 KB Output is correct