#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 |
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 |
83 ms |
21256 KB |
Output is correct |
11 |
Correct |
73 ms |
19364 KB |
Output is correct |
12 |
Correct |
59 ms |
19196 KB |
Output is correct |
13 |
Correct |
1299 ms |
55100 KB |
Output is correct |
14 |
Correct |
1433 ms |
54964 KB |
Output is correct |
15 |
Correct |
126 ms |
19064 KB |
Output is correct |
16 |
Correct |
99 ms |
18932 KB |
Output is correct |
17 |
Correct |
1263 ms |
41612 KB |
Output is correct |
18 |
Correct |
863 ms |
40052 KB |
Output is correct |
19 |
Correct |
1599 ms |
43932 KB |
Output is correct |
20 |
Correct |
1449 ms |
42296 KB |
Output is correct |
21 |
Correct |
1779 ms |
45412 KB |
Output is correct |
22 |
Correct |
1869 ms |
42532 KB |
Output is correct |
23 |
Correct |
1553 ms |
48520 KB |
Output is correct |
24 |
Correct |
2193 ms |
45448 KB |
Output is correct |
25 |
Correct |
2045 ms |
48520 KB |
Output is correct |
26 |
Correct |
2206 ms |
45448 KB |
Output is correct |
27 |
Correct |
183 ms |
19624 KB |
Output is correct |
28 |
Correct |
163 ms |
19352 KB |
Output is correct |
29 |
Correct |
2876 ms |
43048 KB |
Output is correct |
30 |
Correct |
2233 ms |
41564 KB |
Output is correct |
31 |
Correct |
1573 ms |
48500 KB |
Output is correct |
32 |
Correct |
1196 ms |
43916 KB |
Output is correct |
33 |
Correct |
1659 ms |
45412 KB |
Output is correct |
34 |
Correct |
2593 ms |
48484 KB |
Output is correct |
35 |
Correct |
2179 ms |
48520 KB |
Output is correct |
36 |
Correct |
2299 ms |
48520 KB |
Output is correct |
37 |
Correct |
1979 ms |
54664 KB |
Output is correct |
38 |
Correct |
2229 ms |
54664 KB |
Output is correct |
39 |
Correct |
223 ms |
19736 KB |
Output is correct |
40 |
Correct |
199 ms |
19624 KB |
Output is correct |
41 |
Correct |
3553 ms |
46092 KB |
Output is correct |
42 |
Correct |
3043 ms |
46116 KB |
Output is correct |
43 |
Correct |
3063 ms |
54616 KB |
Output is correct |
44 |
Correct |
2773 ms |
54636 KB |
Output is correct |
45 |
Correct |
1816 ms |
54628 KB |
Output is correct |
46 |
Correct |
2289 ms |
54628 KB |
Output is correct |
47 |
Correct |
2193 ms |
54664 KB |
Output is correct |
48 |
Correct |
2869 ms |
54664 KB |
Output is correct |
49 |
Correct |
2726 ms |
54664 KB |
Output is correct |
50 |
Correct |
2243 ms |
54664 KB |
Output is correct |
51 |
Correct |
1796 ms |
54664 KB |
Output is correct |
52 |
Correct |
1313 ms |
54664 KB |
Output is correct |
53 |
Correct |
639 ms |
42428 KB |
Output is correct |
54 |
Correct |
2466 ms |
48516 KB |
Output is correct |
55 |
Correct |
2463 ms |
48484 KB |
Output is correct |
56 |
Correct |
2559 ms |
54628 KB |
Output is correct |
57 |
Correct |
1329 ms |
54436 KB |
Output is correct |