#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e8;
int u[200002], v[200002], ans[200002], dist[100002], R[200002], nes[200002], use[100002];
vector<pair<int, int>> adj[100002];
int main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
int N, M, Q; cin >> N >> M >> Q;
for(int i=1;i<=M;i++)
{
cin >> u[i] >> v[i];
adj[u[i]].push_back({v[i], i});
adj[v[i]].push_back({u[i], i});
}
for(int i=1;i<=Q;i++) cin >> R[i];
for(int i=2;i<=N;i++) dist[i] = INF;
queue<int> q;
q.push(1);
while(!q.empty())
{
int now = q.front(); q.pop();
for(auto uv : adj[now])
{
int i = uv.first;
if(dist[i] > dist[now] + 1)
{
dist[i] = dist[now] + 1;
q.push(i);
}
}
}
for(int i=1;i<=M;i++)
{
if(dist[u[i]] != dist[v[i]]) nes[i] = 1;
}
for(int i=1;i<=Q;i++) nes[R[i]] = 0;
q.push(1);
int tmp = 0;
use[1] = 1;
while(!q.empty())
{
int now = q.front(); q.pop();
tmp++;
for(auto uv : adj[now])
{
if(!nes[uv.second]) continue;
int i = uv.first;
if(dist[i] == dist[now] + 1 && !use[i])
{
q.push(i);
use[i] = 1;
}
}
}
for(int i=Q;i>=1;i--)
{
ans[i] = N - tmp;
if(dist[u[R[i]]] == dist[v[R[i]]]) continue;
nes[R[i]] = 1;
int A, B;
if(dist[u[R[i]]] > dist[v[R[i]]])
{
A = v[R[i]];
B = u[R[i]];
}
else
{
A = u[R[i]];
B = v[R[i]];
}
if(use[A] && !use[B])
{
q.push(B);
while(!q.empty())
{
int now = q.front(); q.pop();
tmp++;
for(auto uv: adj[now])
{
if(!nes[uv.second]) continue;
int j = uv.first;
if(dist[j] == dist[now] + 1 && !use[j])
{
q.push(j);
use[j] = 1;
}
}
}
}
}
for(int i=1;i<=Q;i++) cout << ans[i] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2792 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2792 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
12096 KB |
Output is correct |
2 |
Correct |
99 ms |
14500 KB |
Output is correct |
3 |
Correct |
59 ms |
12212 KB |
Output is correct |
4 |
Correct |
79 ms |
14068 KB |
Output is correct |
5 |
Incorrect |
82 ms |
14128 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2792 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |