#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi; typedef pair<ll, int> pli; typedef pair<ll, pi> plp;
typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;
const int MAX_N = 5e4 + 100;
int N, M, K, Qn;
vector<int> Ks;
vector<pi> Ed[MAX_N];
int Chk[MAX_N];
int main() {
cin >> N >> M >> K >> Qn;
for(int i=0; i<K; i++) {int x; scanf("%d", &x); x--; Ks.push_back(x);}
for(int i=0; i<M; i++) {
int x, y, c; scanf("%d%d%d", &x, &y, &c); x--; y--;
Ed[x].push_back(pi(y, c));
Ed[y].push_back(pi(x, c));
}
vector<vector<pi>> dis(11, vector<pi>(N, pi(INF, -1)));
vector<vector<int>> mar(N, vector<int>());
vector<int> cnt(N, 0);
priority_queue<ti, vector<ti>, greater<ti>> Q;
for(int k : Ks) {
Q.push(ti(0, k, k));
dis[0][k] = pi(0, k);
}
while(!Q.empty()) {
int d, v, wh; tie(d, v, wh) = Q.top(); Q.pop();
if(cnt[v] >= 11) continue;
bool isCan = true; for(int i=0; i<cnt[v]; i++) if(mar[v][i] == wh) {isCan = false; break;}
if(!isCan) continue;
// printf("%d %d %d\n", d, v, wh);
mar[v].push_back(wh);
dis[cnt[v]][v] = pi(d, wh); cnt[v]++;
for(pi &e : Ed[v]) {
int w, c; tie(w, c) = e;
if(cnt[w] >= 11) continue;
Q.push(ti(d+c, w, wh));
// printf("push %d %d %d\n", d+c, w, wh);
}
}
for(int q=1; q<=Qn; q++) {
int s, k;
scanf("%d%d", &s, &k); s--;
for(int i=0; i<k; i++) {
int x; scanf("%d", &x); x--;
Chk[x] = q;
}
for(int i=0; i<11; i++) {
if(Chk[mar[s][i]] != q) {
printf("%d %d\n", dis[i][s].two+1, dis[i][s].one);
break;
}
}
}
return 0;
}
Compilation message
mart.cpp: In function 'int main()':
mart.cpp:24:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=0; i<K; i++) {int x; scanf("%d", &x); x--; Ks.push_back(x);}
^
mart.cpp:26:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int x, y, c; scanf("%d%d%d", &x, &y, &c); x--; y--;
^
mart.cpp:57:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &s, &k); s--;
^
mart.cpp:59:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int x; scanf("%d", &x); x--;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
3392 KB |
Output is correct |
2 |
Correct |
0 ms |
3392 KB |
Output is correct |
3 |
Correct |
0 ms |
3392 KB |
Output is correct |
4 |
Correct |
0 ms |
3392 KB |
Output is correct |
5 |
Correct |
0 ms |
3528 KB |
Output is correct |
6 |
Correct |
0 ms |
3528 KB |
Output is correct |
7 |
Correct |
0 ms |
3524 KB |
Output is correct |
8 |
Correct |
3 ms |
3524 KB |
Output is correct |
9 |
Correct |
59 ms |
8432 KB |
Output is correct |
10 |
Correct |
49 ms |
8428 KB |
Output is correct |
11 |
Correct |
46 ms |
4784 KB |
Output is correct |
12 |
Correct |
46 ms |
4608 KB |
Output is correct |
13 |
Correct |
539 ms |
43152 KB |
Output is correct |
14 |
Correct |
543 ms |
43148 KB |
Output is correct |
15 |
Correct |
153 ms |
12728 KB |
Output is correct |
16 |
Correct |
116 ms |
12164 KB |
Output is correct |
17 |
Correct |
673 ms |
16860 KB |
Output is correct |
18 |
Correct |
409 ms |
15068 KB |
Output is correct |
19 |
Correct |
596 ms |
16724 KB |
Output is correct |
20 |
Correct |
506 ms |
15200 KB |
Output is correct |
21 |
Correct |
619 ms |
16856 KB |
Output is correct |
22 |
Correct |
656 ms |
15376 KB |
Output is correct |
23 |
Correct |
673 ms |
18708 KB |
Output is correct |
24 |
Correct |
793 ms |
18536 KB |
Output is correct |
25 |
Correct |
613 ms |
22744 KB |
Output is correct |
26 |
Correct |
819 ms |
18672 KB |
Output is correct |
27 |
Correct |
179 ms |
13564 KB |
Output is correct |
28 |
Correct |
106 ms |
12836 KB |
Output is correct |
29 |
Correct |
986 ms |
18888 KB |
Output is correct |
30 |
Correct |
866 ms |
16892 KB |
Output is correct |
31 |
Correct |
586 ms |
18456 KB |
Output is correct |
32 |
Correct |
763 ms |
16672 KB |
Output is correct |
33 |
Correct |
733 ms |
18436 KB |
Output is correct |
34 |
Correct |
793 ms |
22284 KB |
Output is correct |
35 |
Correct |
919 ms |
22376 KB |
Output is correct |
36 |
Correct |
909 ms |
22408 KB |
Output is correct |
37 |
Correct |
1026 ms |
22436 KB |
Output is correct |
38 |
Correct |
909 ms |
22456 KB |
Output is correct |
39 |
Correct |
173 ms |
13820 KB |
Output is correct |
40 |
Correct |
189 ms |
13820 KB |
Output is correct |
41 |
Correct |
1263 ms |
22216 KB |
Output is correct |
42 |
Correct |
1073 ms |
22408 KB |
Output is correct |
43 |
Correct |
866 ms |
22088 KB |
Output is correct |
44 |
Correct |
993 ms |
22148 KB |
Output is correct |
45 |
Correct |
796 ms |
22108 KB |
Output is correct |
46 |
Correct |
909 ms |
22176 KB |
Output is correct |
47 |
Correct |
959 ms |
32432 KB |
Output is correct |
48 |
Correct |
779 ms |
32728 KB |
Output is correct |
49 |
Correct |
856 ms |
32572 KB |
Output is correct |
50 |
Correct |
996 ms |
32728 KB |
Output is correct |
51 |
Correct |
809 ms |
32168 KB |
Output is correct |
52 |
Correct |
789 ms |
32200 KB |
Output is correct |
53 |
Correct |
343 ms |
14540 KB |
Output is correct |
54 |
Correct |
889 ms |
22448 KB |
Output is correct |
55 |
Correct |
696 ms |
21916 KB |
Output is correct |
56 |
Correct |
956 ms |
22044 KB |
Output is correct |
57 |
Correct |
593 ms |
42556 KB |
Output is correct |