#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define x first
#define y second
ll N, M, K;
pair<ll, ll> E[200005];
vector<pair<ll, ll>> G[200005];
ll dist[200005];
const ll INF = 1e18;
ll deg[200005];
ll chk[200005];
int main(){
cin.tie(0) -> sync_with_stdio(false);
cin >> N >> M >> K;
for(int i = 1; i <= M; i++){
cin >> E[i].x >> E[i].y;
G[E[i].x].push_back({E[i].y, i});
G[E[i].y].push_back({E[i].x, i});
}
queue<ll> Q;
fill(dist, dist + N + 1, INF);
Q.push(1); dist[1] = 0;
while(!Q.empty()){
ll u = Q.front(); Q.pop();
for(auto i : G[u]){
if(dist[i.x] <= dist[u] + 1) continue;
dist[i.x] = dist[u] + 1;
Q.push(i.x);
}
}
for(int i = 1; i <= M; i++){
if(dist[E[i].x] == dist[E[i].y]) continue;
if(dist[E[i].x] > dist[E[i].y]) swap(E[i].x, E[i].y);
deg[E[i].y]++;
}
ll r = 0;
while(K--){
ll t; cin >> t;
if(!chk[t] && dist[E[t].x] != dist[E[t].y]){
Q.push(t); chk[t] = 1;
while(!Q.empty()){
ll u = Q.front(); Q.pop();
deg[E[u].y]--;
if(deg[E[u].y] == 0){
r++;
for(auto i : G[E[u].y]){
if(chk[i.y] || dist[E[i.y].x] == dist[E[i.y].y]) continue;
chk[i.y] = 1;
Q.push(i.y);
}
}
}
}
cout << r << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5032 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
4 ms |
5332 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5024 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5032 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
4 ms |
5332 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5024 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
114 ms |
21012 KB |
Output is correct |
10 |
Correct |
124 ms |
21048 KB |
Output is correct |
11 |
Correct |
125 ms |
20156 KB |
Output is correct |
12 |
Correct |
137 ms |
20312 KB |
Output is correct |
13 |
Correct |
109 ms |
20716 KB |
Output is correct |
14 |
Correct |
98 ms |
20448 KB |
Output is correct |
15 |
Correct |
74 ms |
16020 KB |
Output is correct |
16 |
Correct |
51 ms |
14720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
22092 KB |
Output is correct |
2 |
Correct |
111 ms |
21848 KB |
Output is correct |
3 |
Correct |
79 ms |
17428 KB |
Output is correct |
4 |
Correct |
106 ms |
20804 KB |
Output is correct |
5 |
Correct |
97 ms |
20544 KB |
Output is correct |
6 |
Correct |
106 ms |
20628 KB |
Output is correct |
7 |
Correct |
55 ms |
14272 KB |
Output is correct |
8 |
Correct |
57 ms |
14136 KB |
Output is correct |
9 |
Correct |
32 ms |
12740 KB |
Output is correct |
10 |
Correct |
29 ms |
12976 KB |
Output is correct |
11 |
Correct |
119 ms |
21140 KB |
Output is correct |
12 |
Correct |
103 ms |
20784 KB |
Output is correct |
13 |
Correct |
109 ms |
20408 KB |
Output is correct |
14 |
Correct |
103 ms |
21864 KB |
Output is correct |
15 |
Correct |
125 ms |
20504 KB |
Output is correct |
16 |
Correct |
124 ms |
21936 KB |
Output is correct |
17 |
Correct |
137 ms |
21748 KB |
Output is correct |
18 |
Correct |
107 ms |
16516 KB |
Output is correct |
19 |
Correct |
160 ms |
26164 KB |
Output is correct |
20 |
Correct |
135 ms |
21620 KB |
Output is correct |
21 |
Correct |
95 ms |
15996 KB |
Output is correct |
22 |
Correct |
70 ms |
15688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5032 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
4 ms |
5332 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5024 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
114 ms |
21012 KB |
Output is correct |
10 |
Correct |
124 ms |
21048 KB |
Output is correct |
11 |
Correct |
125 ms |
20156 KB |
Output is correct |
12 |
Correct |
137 ms |
20312 KB |
Output is correct |
13 |
Correct |
109 ms |
20716 KB |
Output is correct |
14 |
Correct |
98 ms |
20448 KB |
Output is correct |
15 |
Correct |
74 ms |
16020 KB |
Output is correct |
16 |
Correct |
51 ms |
14720 KB |
Output is correct |
17 |
Correct |
112 ms |
22092 KB |
Output is correct |
18 |
Correct |
111 ms |
21848 KB |
Output is correct |
19 |
Correct |
79 ms |
17428 KB |
Output is correct |
20 |
Correct |
106 ms |
20804 KB |
Output is correct |
21 |
Correct |
97 ms |
20544 KB |
Output is correct |
22 |
Correct |
106 ms |
20628 KB |
Output is correct |
23 |
Correct |
55 ms |
14272 KB |
Output is correct |
24 |
Correct |
57 ms |
14136 KB |
Output is correct |
25 |
Correct |
32 ms |
12740 KB |
Output is correct |
26 |
Correct |
29 ms |
12976 KB |
Output is correct |
27 |
Correct |
119 ms |
21140 KB |
Output is correct |
28 |
Correct |
103 ms |
20784 KB |
Output is correct |
29 |
Correct |
109 ms |
20408 KB |
Output is correct |
30 |
Correct |
103 ms |
21864 KB |
Output is correct |
31 |
Correct |
125 ms |
20504 KB |
Output is correct |
32 |
Correct |
124 ms |
21936 KB |
Output is correct |
33 |
Correct |
137 ms |
21748 KB |
Output is correct |
34 |
Correct |
107 ms |
16516 KB |
Output is correct |
35 |
Correct |
160 ms |
26164 KB |
Output is correct |
36 |
Correct |
135 ms |
21620 KB |
Output is correct |
37 |
Correct |
95 ms |
15996 KB |
Output is correct |
38 |
Correct |
70 ms |
15688 KB |
Output is correct |
39 |
Correct |
169 ms |
26624 KB |
Output is correct |
40 |
Correct |
198 ms |
26588 KB |
Output is correct |
41 |
Correct |
111 ms |
20760 KB |
Output is correct |
42 |
Correct |
166 ms |
25952 KB |
Output is correct |
43 |
Correct |
160 ms |
26012 KB |
Output is correct |
44 |
Correct |
164 ms |
25932 KB |
Output is correct |
45 |
Correct |
168 ms |
26004 KB |
Output is correct |
46 |
Correct |
79 ms |
17280 KB |
Output is correct |
47 |
Correct |
79 ms |
16620 KB |
Output is correct |
48 |
Correct |
87 ms |
16456 KB |
Output is correct |
49 |
Correct |
56 ms |
14568 KB |
Output is correct |
50 |
Correct |
53 ms |
14680 KB |
Output is correct |
51 |
Correct |
57 ms |
15160 KB |
Output is correct |
52 |
Correct |
64 ms |
15436 KB |
Output is correct |
53 |
Correct |
61 ms |
14356 KB |
Output is correct |
54 |
Correct |
51 ms |
14748 KB |
Output is correct |