답안 #26981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26981 2017-07-08T07:19:41 Z 검수팍(#1115) Alternative Mart (FXCUP2_mart) C++
1 / 1
4059 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 0 ms 16556 KB Output is correct
6 Correct 3 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 103 ms 21256 KB Output is correct
10 Correct 79 ms 21256 KB Output is correct
11 Correct 86 ms 19364 KB Output is correct
12 Correct 69 ms 19196 KB Output is correct
13 Correct 1253 ms 55100 KB Output is correct
14 Correct 1243 ms 54964 KB Output is correct
15 Correct 143 ms 19064 KB Output is correct
16 Correct 113 ms 18932 KB Output is correct
17 Correct 1723 ms 41612 KB Output is correct
18 Correct 1126 ms 40052 KB Output is correct
19 Correct 1939 ms 43932 KB Output is correct
20 Correct 1419 ms 42296 KB Output is correct
21 Correct 1873 ms 45412 KB Output is correct
22 Correct 1856 ms 42532 KB Output is correct
23 Correct 1903 ms 48520 KB Output is correct
24 Correct 2066 ms 45448 KB Output is correct
25 Correct 1366 ms 48520 KB Output is correct
26 Correct 1433 ms 45448 KB Output is correct
27 Correct 123 ms 19624 KB Output is correct
28 Correct 119 ms 19352 KB Output is correct
29 Correct 1779 ms 43048 KB Output is correct
30 Correct 1389 ms 41564 KB Output is correct
31 Correct 2336 ms 48500 KB Output is correct
32 Correct 2083 ms 43916 KB Output is correct
33 Correct 2256 ms 45412 KB Output is correct
34 Correct 1589 ms 48484 KB Output is correct
35 Correct 1746 ms 48520 KB Output is correct
36 Correct 2323 ms 48520 KB Output is correct
37 Correct 2086 ms 54664 KB Output is correct
38 Correct 2393 ms 54664 KB Output is correct
39 Correct 196 ms 19736 KB Output is correct
40 Correct 216 ms 19624 KB Output is correct
41 Correct 4059 ms 46092 KB Output is correct
42 Correct 2963 ms 46116 KB Output is correct
43 Correct 2439 ms 54616 KB Output is correct
44 Correct 3139 ms 54636 KB Output is correct
45 Correct 2319 ms 54628 KB Output is correct
46 Correct 2873 ms 54628 KB Output is correct
47 Correct 3033 ms 54664 KB Output is correct
48 Correct 2929 ms 54664 KB Output is correct
49 Correct 2739 ms 54664 KB Output is correct
50 Correct 2949 ms 54664 KB Output is correct
51 Correct 1499 ms 54664 KB Output is correct
52 Correct 1856 ms 54664 KB Output is correct
53 Correct 729 ms 42428 KB Output is correct
54 Correct 1956 ms 48516 KB Output is correct
55 Correct 1576 ms 48484 KB Output is correct
56 Correct 1656 ms 54628 KB Output is correct
57 Correct 839 ms 54436 KB Output is correct