답안 #26982

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26982 2017-07-08T07:20:12 Z 검수팍(#1115) Alternative Mart (FXCUP2_mart) C++
1 / 1
3519 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 0 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 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 96 ms 21256 KB Output is correct
10 Correct 73 ms 21256 KB Output is correct
11 Correct 83 ms 19364 KB Output is correct
12 Correct 76 ms 19196 KB Output is correct
13 Correct 1253 ms 55100 KB Output is correct
14 Correct 1329 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 1963 ms 41612 KB Output is correct
18 Correct 1143 ms 40052 KB Output is correct
19 Correct 1929 ms 43932 KB Output is correct
20 Correct 1373 ms 42296 KB Output is correct
21 Correct 1516 ms 45412 KB Output is correct
22 Correct 1609 ms 42532 KB Output is correct
23 Correct 1436 ms 48520 KB Output is correct
24 Correct 1939 ms 45448 KB Output is correct
25 Correct 1443 ms 48520 KB Output is correct
26 Correct 1553 ms 45448 KB Output is correct
27 Correct 176 ms 19624 KB Output is correct
28 Correct 176 ms 19352 KB Output is correct
29 Correct 2896 ms 43048 KB Output is correct
30 Correct 2123 ms 41564 KB Output is correct
31 Correct 1576 ms 48500 KB Output is correct
32 Correct 2213 ms 43916 KB Output is correct
33 Correct 1979 ms 45412 KB Output is correct
34 Correct 1823 ms 48484 KB Output is correct
35 Correct 1869 ms 48520 KB Output is correct
36 Correct 1933 ms 48520 KB Output is correct
37 Correct 1573 ms 54664 KB Output is correct
38 Correct 2283 ms 54664 KB Output is correct
39 Correct 233 ms 19736 KB Output is correct
40 Correct 223 ms 19624 KB Output is correct
41 Correct 3519 ms 46092 KB Output is correct
42 Correct 2876 ms 46116 KB Output is correct
43 Correct 1739 ms 54616 KB Output is correct
44 Correct 2719 ms 54636 KB Output is correct
45 Correct 1909 ms 54628 KB Output is correct
46 Correct 1723 ms 54628 KB Output is correct
47 Correct 2516 ms 54664 KB Output is correct
48 Correct 2729 ms 54664 KB Output is correct
49 Correct 2999 ms 54664 KB Output is correct
50 Correct 3169 ms 54664 KB Output is correct
51 Correct 1819 ms 54664 KB Output is correct
52 Correct 1623 ms 54664 KB Output is correct
53 Correct 733 ms 42428 KB Output is correct
54 Correct 2639 ms 48516 KB Output is correct
55 Correct 2733 ms 48484 KB Output is correct
56 Correct 3179 ms 54628 KB Output is correct
57 Correct 1663 ms 54436 KB Output is correct