#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int MX=100010, inf=2e9;
int n, m, q;
int Q[MX];
struct node {
int dist, cnt, sub;
} D[MX];
struct edge {
int u, v, c, idx;
} E[2*MX];
vector<int> G[MX];
int init_dist[MX], ans;
bool do_upt(int r){
int a=E[r].u, b=E[r].v;
if(D[a].dist==D[b].dist) return false;
if(D[a].dist>D[b].dist) swap(a,b);
// D[b].dist == D[a].dist+1
D[b].cnt-=D[a].cnt;
return D[b].cnt==0;
}
void upt(){
// dijk?
for(int i=1; i<=n; i++)
D[i]={inf, 0, 0};
D[1]={0,1,0};
queue<int> Q; Q.push(1);
while(!Q.empty()){
int v=Q.front(); Q.pop();
for(int e:G[v]){
int x=E[e].u, y=E[e].v, z=(x==v ? y : x);
int dvz=D[v].dist+E[e].c, dz=D[z].dist;
if(dvz>dz) continue;
if(dvz==dz) D[z].cnt+=D[v].cnt;
if(dvz<dz){
D[z]={dvz, D[v].cnt, 0};
Q.push(z);
}
}
}
ans=0;
for(int i=1; i<=n; i++)
if(init_dist[i]!=D[i].dist) ans++;
}
void init(){
upt();
for(int i=1; i<=n; i++)
init_dist[i]=D[i].dist;
ans=0;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>m>>q;
for(int i=1, u, v; i<=m; i++){
cin>>u>>v;
E[i]={u,v,1,i};
G[u].push_back(i);
G[v].push_back(i);
}
init();
for(int i=1, r; i<=q; i++){
cin>>r;
E[r].c=2;
if(do_upt(r)) upt();
cout<<ans<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
5 ms |
2972 KB |
Output is correct |
4 |
Correct |
4 ms |
2972 KB |
Output is correct |
5 |
Correct |
6 ms |
3048 KB |
Output is correct |
6 |
Correct |
5 ms |
3048 KB |
Output is correct |
7 |
Correct |
4 ms |
3048 KB |
Output is correct |
8 |
Incorrect |
4 ms |
3048 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
5 ms |
2972 KB |
Output is correct |
4 |
Correct |
4 ms |
2972 KB |
Output is correct |
5 |
Correct |
6 ms |
3048 KB |
Output is correct |
6 |
Correct |
5 ms |
3048 KB |
Output is correct |
7 |
Correct |
4 ms |
3048 KB |
Output is correct |
8 |
Incorrect |
4 ms |
3048 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1485 ms |
12184 KB |
Output is correct |
2 |
Correct |
1732 ms |
12236 KB |
Output is correct |
3 |
Correct |
504 ms |
12236 KB |
Output is correct |
4 |
Correct |
1473 ms |
12236 KB |
Output is correct |
5 |
Correct |
1148 ms |
12236 KB |
Output is correct |
6 |
Correct |
1282 ms |
12236 KB |
Output is correct |
7 |
Correct |
1141 ms |
12236 KB |
Output is correct |
8 |
Correct |
1245 ms |
12236 KB |
Output is correct |
9 |
Correct |
269 ms |
12236 KB |
Output is correct |
10 |
Correct |
378 ms |
12236 KB |
Output is correct |
11 |
Execution timed out |
2572 ms |
12236 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
5 ms |
2972 KB |
Output is correct |
4 |
Correct |
4 ms |
2972 KB |
Output is correct |
5 |
Correct |
6 ms |
3048 KB |
Output is correct |
6 |
Correct |
5 ms |
3048 KB |
Output is correct |
7 |
Correct |
4 ms |
3048 KB |
Output is correct |
8 |
Incorrect |
4 ms |
3048 KB |
Output isn't correct |