# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
502299 |
2022-01-05T17:55:17 Z |
benedict0724 |
None (JOI16_ho_t3) |
C++17 |
|
147 ms |
18592 KB |
#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);
use[B] = 1;
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";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2812 KB |
Output is correct |
4 |
Correct |
2 ms |
2672 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2812 KB |
Output is correct |
4 |
Correct |
2 ms |
2672 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
104 ms |
14384 KB |
Output is correct |
10 |
Correct |
130 ms |
14560 KB |
Output is correct |
11 |
Correct |
111 ms |
13996 KB |
Output is correct |
12 |
Correct |
125 ms |
14104 KB |
Output is correct |
13 |
Correct |
113 ms |
14200 KB |
Output is correct |
14 |
Correct |
118 ms |
14148 KB |
Output is correct |
15 |
Correct |
83 ms |
10012 KB |
Output is correct |
16 |
Correct |
56 ms |
8936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
13708 KB |
Output is correct |
2 |
Correct |
136 ms |
14484 KB |
Output is correct |
3 |
Correct |
75 ms |
12172 KB |
Output is correct |
4 |
Correct |
94 ms |
14024 KB |
Output is correct |
5 |
Correct |
82 ms |
14160 KB |
Output is correct |
6 |
Correct |
118 ms |
14148 KB |
Output is correct |
7 |
Correct |
58 ms |
8932 KB |
Output is correct |
8 |
Correct |
53 ms |
8900 KB |
Output is correct |
9 |
Correct |
25 ms |
8560 KB |
Output is correct |
10 |
Correct |
25 ms |
8656 KB |
Output is correct |
11 |
Correct |
102 ms |
14768 KB |
Output is correct |
12 |
Correct |
103 ms |
14144 KB |
Output is correct |
13 |
Correct |
84 ms |
13828 KB |
Output is correct |
14 |
Correct |
108 ms |
14760 KB |
Output is correct |
15 |
Correct |
112 ms |
14320 KB |
Output is correct |
16 |
Correct |
112 ms |
13904 KB |
Output is correct |
17 |
Correct |
128 ms |
14872 KB |
Output is correct |
18 |
Correct |
71 ms |
10780 KB |
Output is correct |
19 |
Correct |
147 ms |
18128 KB |
Output is correct |
20 |
Correct |
114 ms |
14940 KB |
Output is correct |
21 |
Correct |
68 ms |
9884 KB |
Output is correct |
22 |
Correct |
60 ms |
9796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2812 KB |
Output is correct |
4 |
Correct |
2 ms |
2672 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
104 ms |
14384 KB |
Output is correct |
10 |
Correct |
130 ms |
14560 KB |
Output is correct |
11 |
Correct |
111 ms |
13996 KB |
Output is correct |
12 |
Correct |
125 ms |
14104 KB |
Output is correct |
13 |
Correct |
113 ms |
14200 KB |
Output is correct |
14 |
Correct |
118 ms |
14148 KB |
Output is correct |
15 |
Correct |
83 ms |
10012 KB |
Output is correct |
16 |
Correct |
56 ms |
8936 KB |
Output is correct |
17 |
Correct |
127 ms |
13708 KB |
Output is correct |
18 |
Correct |
136 ms |
14484 KB |
Output is correct |
19 |
Correct |
75 ms |
12172 KB |
Output is correct |
20 |
Correct |
94 ms |
14024 KB |
Output is correct |
21 |
Correct |
82 ms |
14160 KB |
Output is correct |
22 |
Correct |
118 ms |
14148 KB |
Output is correct |
23 |
Correct |
58 ms |
8932 KB |
Output is correct |
24 |
Correct |
53 ms |
8900 KB |
Output is correct |
25 |
Correct |
25 ms |
8560 KB |
Output is correct |
26 |
Correct |
25 ms |
8656 KB |
Output is correct |
27 |
Correct |
102 ms |
14768 KB |
Output is correct |
28 |
Correct |
103 ms |
14144 KB |
Output is correct |
29 |
Correct |
84 ms |
13828 KB |
Output is correct |
30 |
Correct |
108 ms |
14760 KB |
Output is correct |
31 |
Correct |
112 ms |
14320 KB |
Output is correct |
32 |
Correct |
112 ms |
13904 KB |
Output is correct |
33 |
Correct |
128 ms |
14872 KB |
Output is correct |
34 |
Correct |
71 ms |
10780 KB |
Output is correct |
35 |
Correct |
147 ms |
18128 KB |
Output is correct |
36 |
Correct |
114 ms |
14940 KB |
Output is correct |
37 |
Correct |
68 ms |
9884 KB |
Output is correct |
38 |
Correct |
60 ms |
9796 KB |
Output is correct |
39 |
Correct |
136 ms |
18592 KB |
Output is correct |
40 |
Correct |
141 ms |
18500 KB |
Output is correct |
41 |
Correct |
79 ms |
14200 KB |
Output is correct |
42 |
Correct |
138 ms |
18112 KB |
Output is correct |
43 |
Correct |
118 ms |
18104 KB |
Output is correct |
44 |
Correct |
119 ms |
18036 KB |
Output is correct |
45 |
Correct |
146 ms |
18104 KB |
Output is correct |
46 |
Correct |
59 ms |
11464 KB |
Output is correct |
47 |
Correct |
59 ms |
10936 KB |
Output is correct |
48 |
Correct |
58 ms |
10832 KB |
Output is correct |
49 |
Correct |
40 ms |
10336 KB |
Output is correct |
50 |
Correct |
42 ms |
10256 KB |
Output is correct |
51 |
Correct |
44 ms |
10836 KB |
Output is correct |
52 |
Correct |
46 ms |
10936 KB |
Output is correct |
53 |
Correct |
52 ms |
10132 KB |
Output is correct |
54 |
Correct |
40 ms |
10272 KB |
Output is correct |