답안 #27046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27046 2017-07-09T06:11:16 Z 검수컵(#1129) Alternative Mart (FXCUP2_mart) C++
1 / 1
3319 ms 55100 KB
#include<stdio.h>
#include<memory.h>
#include<vector>
#include<queue>
#include<set>
using namespace std;

struct nod {
	int st, ix, dst;
	nod(int st_, int ix_, int dst_){ st=st_, ix=ix_, dst=dst_; }
	bool operator< (const nod& c) const {
		if(dst != c.dst) return dst > c.dst;
		return st > c.st;
	}
};

priority_queue<nod> pq;

int N, M, K, Q;
int endp[406060], val[406060], prv[406060], top[101010], ecn;
int dist[101010][11], dnum[101010][11], dcn[101010];
set<pair<int,int> > chk;

void edge(int s, int e, int v){
	endp[ecn]=e, val[ecn]=v, prv[ecn]=top[s], top[s]=ecn++;
}

int st, x, close[11], ban[101010];

int main(){
	scanf("%d%d%d%d", &N, &M, &K, &Q);
	for(int i=1; i<=N; i++) top[i]=-1;
	memset(dist, 0x3f, sizeof(dist));
	for(int i=K; i--;){
		int a; scanf("%d", &a);
		pq.push(nod(a, a, 0));
	}
	for(int i=M; i--;){
		int s, e, v;
		scanf("%d%d%d", &s, &e, &v);
		edge(s, e, v), edge(e, s, v);
	}
	while(!pq.empty()){
		nod cur = pq.top(); pq.pop();
		if(dcn[cur.ix] >= 11) continue;
		if(chk.find(make_pair(cur.ix, cur.st)) != chk.end()) continue;
		int dix = dcn[cur.ix];
		dist[cur.ix][dix] = cur.dst, dnum[cur.ix][dix] = cur.st, dcn[cur.ix]++;
		chk.insert(make_pair(cur.ix, cur.st));
		for(int i=top[cur.ix]; i>=0; i=prv[i]) pq.push(nod(cur.st, endp[i], cur.dst+val[i]));
	}

	for(int t=Q; t--;){
		scanf("%d%d", &st, &x);
		for(int i=0; i<x; i++) scanf("%d", &close[i]), ban[close[i]]=1;
		for(int i=0; i<=10; i++){
			if(ban[dnum[st][i]]) continue;
			printf("%d %d\n", dnum[st][i], dist[st][i]);
			break;
		}
		for(int i=0; i<x; i++) ban[close[i]]=0;
	}
	return 0;
}

Compilation message

mart.cpp: In function 'int main()':
mart.cpp:31: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:35:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a; scanf("%d", &a);
                         ^
mart.cpp:40:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &s, &e, &v);
                              ^
mart.cpp:54:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &st, &x);
                         ^
mart.cpp:55:65: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i=0; i<x; i++) scanf("%d", &close[i]), ban[close[i]]=1;
                                                                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16556 KB Output is correct
2 Correct 0 ms 16556 KB Output is correct
3 Correct 0 ms 16556 KB Output is correct
4 Correct 0 ms 16556 KB Output is correct
5 Correct 3 ms 16556 KB Output is correct
6 Correct 0 ms 16556 KB Output is correct
7 Correct 3 ms 16836 KB Output is correct
8 Correct 3 ms 16820 KB Output is correct
9 Correct 89 ms 21256 KB Output is correct
10 Correct 93 ms 21256 KB Output is correct
11 Correct 76 ms 19364 KB Output is correct
12 Correct 66 ms 19196 KB Output is correct
13 Correct 1303 ms 55100 KB Output is correct
14 Correct 1599 ms 54964 KB Output is correct
15 Correct 133 ms 19064 KB Output is correct
16 Correct 116 ms 18932 KB Output is correct
17 Correct 1836 ms 41612 KB Output is correct
18 Correct 1113 ms 40052 KB Output is correct
19 Correct 1586 ms 43932 KB Output is correct
20 Correct 1423 ms 42296 KB Output is correct
21 Correct 1976 ms 45412 KB Output is correct
22 Correct 1889 ms 42532 KB Output is correct
23 Correct 1779 ms 48520 KB Output is correct
24 Correct 2309 ms 45448 KB Output is correct
25 Correct 1929 ms 48520 KB Output is correct
26 Correct 2253 ms 45448 KB Output is correct
27 Correct 199 ms 19624 KB Output is correct
28 Correct 163 ms 19352 KB Output is correct
29 Correct 3019 ms 43048 KB Output is correct
30 Correct 2313 ms 41564 KB Output is correct
31 Correct 1549 ms 48500 KB Output is correct
32 Correct 2106 ms 43916 KB Output is correct
33 Correct 2163 ms 45412 KB Output is correct
34 Correct 2496 ms 48484 KB Output is correct
35 Correct 2519 ms 48520 KB Output is correct
36 Correct 2476 ms 48520 KB Output is correct
37 Correct 1879 ms 54664 KB Output is correct
38 Correct 2316 ms 54664 KB Output is correct
39 Correct 229 ms 19736 KB Output is correct
40 Correct 256 ms 19624 KB Output is correct
41 Correct 3319 ms 46092 KB Output is correct
42 Correct 3056 ms 46116 KB Output is correct
43 Correct 3053 ms 54616 KB Output is correct
44 Correct 3089 ms 54636 KB Output is correct
45 Correct 3179 ms 54628 KB Output is correct
46 Correct 2489 ms 54628 KB Output is correct
47 Correct 2983 ms 54664 KB Output is correct
48 Correct 3043 ms 54664 KB Output is correct
49 Correct 2963 ms 54664 KB Output is correct
50 Correct 2723 ms 54664 KB Output is correct
51 Correct 1973 ms 54664 KB Output is correct
52 Correct 1856 ms 54664 KB Output is correct
53 Correct 633 ms 42428 KB Output is correct
54 Correct 2603 ms 48516 KB Output is correct
55 Correct 2519 ms 48484 KB Output is correct
56 Correct 3129 ms 54628 KB Output is correct
57 Correct 1266 ms 54436 KB Output is correct