Submission #26983

# Submission time Handle Problem Language Result Execution time Memory
26983 2017-07-08T07:26:39 Z 검수팍(#1115) Alternative Mart (FXCUP2_mart) C++
1 / 1
4119 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]){
			if(chk.find(make_pair(endp[i], cur.st)) != chk.end()) continue;
			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:57: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:58: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;
                                                                 ^
# Verdict Execution time Memory 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 3 ms 16556 KB Output is correct
5 Correct 3 ms 16556 KB Output is correct
6 Correct 3 ms 16556 KB Output is correct
7 Correct 6 ms 16820 KB Output is correct
8 Correct 3 ms 16820 KB Output is correct
9 Correct 133 ms 21256 KB Output is correct
10 Correct 66 ms 18952 KB Output is correct
11 Correct 103 ms 19252 KB Output is correct
12 Correct 79 ms 19196 KB Output is correct
13 Correct 2393 ms 55100 KB Output is correct
14 Correct 1956 ms 55096 KB Output is correct
15 Correct 136 ms 19064 KB Output is correct
16 Correct 106 ms 18932 KB Output is correct
17 Correct 1263 ms 40744 KB Output is correct
18 Correct 1286 ms 40052 KB Output is correct
19 Correct 1559 ms 43872 KB Output is correct
20 Correct 1566 ms 42296 KB Output is correct
21 Correct 2043 ms 43876 KB Output is correct
22 Correct 2489 ms 42468 KB Output is correct
23 Correct 2689 ms 45448 KB Output is correct
24 Correct 2736 ms 43912 KB Output is correct
25 Correct 2603 ms 45448 KB Output is correct
26 Correct 2136 ms 43912 KB Output is correct
27 Correct 183 ms 19272 KB Output is correct
28 Correct 159 ms 19172 KB Output is correct
29 Correct 2973 ms 41540 KB Output is correct
30 Correct 2633 ms 40716 KB Output is correct
31 Correct 2863 ms 45460 KB Output is correct
32 Correct 2389 ms 43068 KB Output is correct
33 Correct 2256 ms 45412 KB Output is correct
34 Correct 2536 ms 48484 KB Output is correct
35 Correct 2946 ms 48520 KB Output is correct
36 Correct 3429 ms 48520 KB Output is correct
37 Correct 3499 ms 48520 KB Output is correct
38 Correct 3089 ms 48520 KB Output is correct
39 Correct 196 ms 19368 KB Output is correct
40 Correct 196 ms 19268 KB Output is correct
41 Correct 3706 ms 43036 KB Output is correct
42 Correct 3913 ms 43072 KB Output is correct
43 Correct 4049 ms 48488 KB Output is correct
44 Correct 2766 ms 48516 KB Output is correct
45 Correct 3849 ms 48484 KB Output is correct
46 Correct 2879 ms 48484 KB Output is correct
47 Correct 4119 ms 54664 KB Output is correct
48 Correct 3859 ms 54664 KB Output is correct
49 Correct 4046 ms 54664 KB Output is correct
50 Correct 2976 ms 54664 KB Output is correct
51 Correct 2583 ms 54664 KB Output is correct
52 Correct 3156 ms 54664 KB Output is correct
53 Correct 796 ms 42428 KB Output is correct
54 Correct 3949 ms 45384 KB Output is correct
55 Correct 2176 ms 48484 KB Output is correct
56 Correct 2396 ms 48484 KB Output is correct
57 Correct 889 ms 35608 KB Output is correct