This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |