#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
struct nosun{
int from,to;
};
struct edge{
int v,idx;
};
int N,M,Q,Ans;
nosun Nosun[200001];
vector<edge> Edge[100001];
int Dist[100001];
queue<int> Queue;
int Cnt[100001];
bool Visited[200001];
bool f(int idx){
return (Dist[Nosun[idx].from]==Dist[Nosun[idx].to]);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>N>>M>>Q;
for (int i=1; i<=N; i++)
Dist[i]=INF;
for (int i=1; i<=M; i++){
cin>>Nosun[i].from>>Nosun[i].to;
Edge[Nosun[i].from].push_back({Nosun[i].to,i});
Edge[Nosun[i].to].push_back({Nosun[i].from,i});
}
Dist[1]=0;
Queue.push(1);
while (!Queue.empty()){
int t=Queue.front();
Queue.pop();
for (edge i:Edge[t]){
if (Dist[i.v]>Dist[t]+1){
Dist[i.v]=Dist[t]+1;
Queue.push(i.v);
}
}
}
for (int i=1; i<=M; i++){
if (f(i))
continue;
if (Dist[Nosun[i].from]>Dist[Nosun[i].to])
swap(Nosun[i].from,Nosun[i].to);
Cnt[Nosun[i].to]++;
}
while (Q--){
int r;
cin>>r;
if (!f(r)&&!Visited[r])
Queue.push(r);
while (!Queue.empty()){
int t=Queue.front();
Queue.pop();
Visited[t]=true;
if (--Cnt[Nosun[t].to]==0){
Ans++;
for (edge i:Edge[Nosun[t].to]){
if (f(i.idx)||Visited[i.idx])
continue;
Queue.push(i.idx);
}
}
}
cout<<Ans<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2680 KB |
Output is correct |
3 |
Correct |
2 ms |
2820 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
1 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
1 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2680 KB |
Output is correct |
3 |
Correct |
2 ms |
2820 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
1 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
1 ms |
2636 KB |
Output is correct |
9 |
Correct |
83 ms |
11608 KB |
Output is correct |
10 |
Correct |
80 ms |
11580 KB |
Output is correct |
11 |
Correct |
82 ms |
11064 KB |
Output is correct |
12 |
Correct |
71 ms |
11288 KB |
Output is correct |
13 |
Correct |
79 ms |
11468 KB |
Output is correct |
14 |
Correct |
82 ms |
11236 KB |
Output is correct |
15 |
Correct |
44 ms |
8388 KB |
Output is correct |
16 |
Correct |
33 ms |
7576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
11624 KB |
Output is correct |
2 |
Correct |
93 ms |
11636 KB |
Output is correct |
3 |
Correct |
55 ms |
9788 KB |
Output is correct |
4 |
Correct |
69 ms |
11332 KB |
Output is correct |
5 |
Correct |
69 ms |
11336 KB |
Output is correct |
6 |
Correct |
70 ms |
11332 KB |
Output is correct |
7 |
Correct |
38 ms |
7612 KB |
Output is correct |
8 |
Correct |
41 ms |
7496 KB |
Output is correct |
9 |
Correct |
24 ms |
7624 KB |
Output is correct |
10 |
Correct |
24 ms |
8172 KB |
Output is correct |
11 |
Correct |
79 ms |
11660 KB |
Output is correct |
12 |
Correct |
87 ms |
11544 KB |
Output is correct |
13 |
Correct |
82 ms |
11212 KB |
Output is correct |
14 |
Correct |
90 ms |
11832 KB |
Output is correct |
15 |
Correct |
88 ms |
11404 KB |
Output is correct |
16 |
Correct |
78 ms |
11160 KB |
Output is correct |
17 |
Correct |
106 ms |
11260 KB |
Output is correct |
18 |
Correct |
72 ms |
8684 KB |
Output is correct |
19 |
Correct |
145 ms |
13028 KB |
Output is correct |
20 |
Correct |
114 ms |
11204 KB |
Output is correct |
21 |
Correct |
61 ms |
8388 KB |
Output is correct |
22 |
Correct |
62 ms |
8292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2680 KB |
Output is correct |
3 |
Correct |
2 ms |
2820 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
1 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
1 ms |
2636 KB |
Output is correct |
9 |
Correct |
83 ms |
11608 KB |
Output is correct |
10 |
Correct |
80 ms |
11580 KB |
Output is correct |
11 |
Correct |
82 ms |
11064 KB |
Output is correct |
12 |
Correct |
71 ms |
11288 KB |
Output is correct |
13 |
Correct |
79 ms |
11468 KB |
Output is correct |
14 |
Correct |
82 ms |
11236 KB |
Output is correct |
15 |
Correct |
44 ms |
8388 KB |
Output is correct |
16 |
Correct |
33 ms |
7576 KB |
Output is correct |
17 |
Correct |
78 ms |
11624 KB |
Output is correct |
18 |
Correct |
93 ms |
11636 KB |
Output is correct |
19 |
Correct |
55 ms |
9788 KB |
Output is correct |
20 |
Correct |
69 ms |
11332 KB |
Output is correct |
21 |
Correct |
69 ms |
11336 KB |
Output is correct |
22 |
Correct |
70 ms |
11332 KB |
Output is correct |
23 |
Correct |
38 ms |
7612 KB |
Output is correct |
24 |
Correct |
41 ms |
7496 KB |
Output is correct |
25 |
Correct |
24 ms |
7624 KB |
Output is correct |
26 |
Correct |
24 ms |
8172 KB |
Output is correct |
27 |
Correct |
79 ms |
11660 KB |
Output is correct |
28 |
Correct |
87 ms |
11544 KB |
Output is correct |
29 |
Correct |
82 ms |
11212 KB |
Output is correct |
30 |
Correct |
90 ms |
11832 KB |
Output is correct |
31 |
Correct |
88 ms |
11404 KB |
Output is correct |
32 |
Correct |
78 ms |
11160 KB |
Output is correct |
33 |
Correct |
106 ms |
11260 KB |
Output is correct |
34 |
Correct |
72 ms |
8684 KB |
Output is correct |
35 |
Correct |
145 ms |
13028 KB |
Output is correct |
36 |
Correct |
114 ms |
11204 KB |
Output is correct |
37 |
Correct |
61 ms |
8388 KB |
Output is correct |
38 |
Correct |
62 ms |
8292 KB |
Output is correct |
39 |
Correct |
153 ms |
13348 KB |
Output is correct |
40 |
Correct |
137 ms |
13380 KB |
Output is correct |
41 |
Correct |
105 ms |
10448 KB |
Output is correct |
42 |
Correct |
132 ms |
15868 KB |
Output is correct |
43 |
Correct |
125 ms |
15944 KB |
Output is correct |
44 |
Correct |
133 ms |
15968 KB |
Output is correct |
45 |
Correct |
140 ms |
15940 KB |
Output is correct |
46 |
Correct |
69 ms |
10292 KB |
Output is correct |
47 |
Correct |
61 ms |
9780 KB |
Output is correct |
48 |
Correct |
58 ms |
9764 KB |
Output is correct |
49 |
Correct |
56 ms |
9372 KB |
Output is correct |
50 |
Correct |
59 ms |
9400 KB |
Output is correct |
51 |
Correct |
54 ms |
9900 KB |
Output is correct |
52 |
Correct |
50 ms |
9908 KB |
Output is correct |
53 |
Correct |
45 ms |
9244 KB |
Output is correct |
54 |
Correct |
59 ms |
9384 KB |
Output is correct |