# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
94080 |
2019-01-15T18:56:27 Z |
brcode |
None (JOI16_ho_t3) |
C++14 |
|
616 ms |
27592 KB |
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
const long long MAXN = 200100;
const long long MOD = 1e9 + 7;
vector<long long> v1[MAXN];
long long fenwick[MAXN + 2];
long long arr[MAXN];
long long h[MAXN];
int query[MAXN];
vector<int> ord;
long long n,m,q;
vector<int> g2[MAXN];
bool ok[MAXN];
int actual[MAXN];
bool notok[MAXN];
long long ans;
vector<pair<int,int>> edges;
int dis[MAXN];
void bfs1(int s){
for(int i=1;i<=n;i++){
dis[i] = -1;
}
dis[s] = 0;
queue<int> q1;
q1.push(s);
while(!q1.empty()){
int curr = q1.front();
q1.pop();
for(auto x:v1[curr]){
if(dis[x] == -1){
dis[x] = 1+dis[curr];
q1.push(x);
}
}
}
}
int bfs2(int a,int b){
if(dis[a] == dis[b]){
return 0;
}
if(dis[a]>dis[b]){
swap(a,b);
}
g2[a].push_back(b);
int res= 0;
if(ok[a]){
queue<int> q1;
q1.push(b);
while(!q1.empty()){
int v = q1.front();
q1.pop();
if(ok[v]){
continue;
}
ok[v] = true;
res++;
for(auto x:g2[v]){
q1.push(x);
}
}
}
return res;
}
int main() {
cin>>n>>m>>q;
//edges.push_back(make_pair(0,0));
for(int i=0;i<m;i++){
int x,y;
cin>>x>>y;
x--;
y--;
v1[x].push_back(y);
v1[y].push_back(x);
edges.push_back(make_pair(x,y));
}
bfs1(0);
for(int i=0;i<q;i++){
cin>>query[i];
query[i]--;
}
for(int i=0;i<=q;i++){
notok[i] = false;
}
for(int i=0;i<q;i++){
ord.push_back(query[i]);
notok[query[i]] = true;
}
for(int i=0;i<m;i++){
if(!notok[i]){
ord.push_back(i);
}
}
int last = 0;
ok[0] = true;
actual[m] = 0;
for(int i=m-1;i>=0;i--){
int a = edges[ord[i]].first;
int b = edges[ord[i]].second;
// cout<<a<<" "<<b<<endl;
int tempans = bfs2(a,b);
actual[i] = tempans+ last;
last = actual[i];
}
for(int i=0;i<q;i++){
cout<<n-1-actual[i+1]<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9720 KB |
Output is correct |
3 |
Correct |
12 ms |
9976 KB |
Output is correct |
4 |
Correct |
10 ms |
9720 KB |
Output is correct |
5 |
Correct |
11 ms |
9848 KB |
Output is correct |
6 |
Correct |
10 ms |
9720 KB |
Output is correct |
7 |
Correct |
9 ms |
9764 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9720 KB |
Output is correct |
3 |
Correct |
12 ms |
9976 KB |
Output is correct |
4 |
Correct |
10 ms |
9720 KB |
Output is correct |
5 |
Correct |
11 ms |
9848 KB |
Output is correct |
6 |
Correct |
10 ms |
9720 KB |
Output is correct |
7 |
Correct |
9 ms |
9764 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
9 |
Correct |
248 ms |
23648 KB |
Output is correct |
10 |
Correct |
298 ms |
23664 KB |
Output is correct |
11 |
Correct |
252 ms |
23652 KB |
Output is correct |
12 |
Correct |
255 ms |
23652 KB |
Output is correct |
13 |
Correct |
278 ms |
23908 KB |
Output is correct |
14 |
Correct |
269 ms |
24272 KB |
Output is correct |
15 |
Correct |
159 ms |
20268 KB |
Output is correct |
16 |
Correct |
116 ms |
19460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
23716 KB |
Output is correct |
2 |
Correct |
260 ms |
23764 KB |
Output is correct |
3 |
Correct |
237 ms |
20632 KB |
Output is correct |
4 |
Correct |
245 ms |
23764 KB |
Output is correct |
5 |
Correct |
241 ms |
24296 KB |
Output is correct |
6 |
Correct |
269 ms |
24464 KB |
Output is correct |
7 |
Correct |
121 ms |
19436 KB |
Output is correct |
8 |
Correct |
140 ms |
19304 KB |
Output is correct |
9 |
Correct |
96 ms |
16488 KB |
Output is correct |
10 |
Correct |
97 ms |
16704 KB |
Output is correct |
11 |
Correct |
393 ms |
24312 KB |
Output is correct |
12 |
Correct |
323 ms |
23780 KB |
Output is correct |
13 |
Correct |
330 ms |
23268 KB |
Output is correct |
14 |
Correct |
342 ms |
24548 KB |
Output is correct |
15 |
Correct |
377 ms |
24420 KB |
Output is correct |
16 |
Correct |
352 ms |
23924 KB |
Output is correct |
17 |
Correct |
448 ms |
24540 KB |
Output is correct |
18 |
Correct |
309 ms |
20976 KB |
Output is correct |
19 |
Correct |
526 ms |
27392 KB |
Output is correct |
20 |
Correct |
479 ms |
24676 KB |
Output is correct |
21 |
Correct |
252 ms |
20164 KB |
Output is correct |
22 |
Correct |
248 ms |
20008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9720 KB |
Output is correct |
3 |
Correct |
12 ms |
9976 KB |
Output is correct |
4 |
Correct |
10 ms |
9720 KB |
Output is correct |
5 |
Correct |
11 ms |
9848 KB |
Output is correct |
6 |
Correct |
10 ms |
9720 KB |
Output is correct |
7 |
Correct |
9 ms |
9764 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
9 |
Correct |
248 ms |
23648 KB |
Output is correct |
10 |
Correct |
298 ms |
23664 KB |
Output is correct |
11 |
Correct |
252 ms |
23652 KB |
Output is correct |
12 |
Correct |
255 ms |
23652 KB |
Output is correct |
13 |
Correct |
278 ms |
23908 KB |
Output is correct |
14 |
Correct |
269 ms |
24272 KB |
Output is correct |
15 |
Correct |
159 ms |
20268 KB |
Output is correct |
16 |
Correct |
116 ms |
19460 KB |
Output is correct |
17 |
Correct |
212 ms |
23716 KB |
Output is correct |
18 |
Correct |
260 ms |
23764 KB |
Output is correct |
19 |
Correct |
237 ms |
20632 KB |
Output is correct |
20 |
Correct |
245 ms |
23764 KB |
Output is correct |
21 |
Correct |
241 ms |
24296 KB |
Output is correct |
22 |
Correct |
269 ms |
24464 KB |
Output is correct |
23 |
Correct |
121 ms |
19436 KB |
Output is correct |
24 |
Correct |
140 ms |
19304 KB |
Output is correct |
25 |
Correct |
96 ms |
16488 KB |
Output is correct |
26 |
Correct |
97 ms |
16704 KB |
Output is correct |
27 |
Correct |
393 ms |
24312 KB |
Output is correct |
28 |
Correct |
323 ms |
23780 KB |
Output is correct |
29 |
Correct |
330 ms |
23268 KB |
Output is correct |
30 |
Correct |
342 ms |
24548 KB |
Output is correct |
31 |
Correct |
377 ms |
24420 KB |
Output is correct |
32 |
Correct |
352 ms |
23924 KB |
Output is correct |
33 |
Correct |
448 ms |
24540 KB |
Output is correct |
34 |
Correct |
309 ms |
20976 KB |
Output is correct |
35 |
Correct |
526 ms |
27392 KB |
Output is correct |
36 |
Correct |
479 ms |
24676 KB |
Output is correct |
37 |
Correct |
252 ms |
20164 KB |
Output is correct |
38 |
Correct |
248 ms |
20008 KB |
Output is correct |
39 |
Correct |
616 ms |
27024 KB |
Output is correct |
40 |
Correct |
611 ms |
26932 KB |
Output is correct |
41 |
Correct |
415 ms |
22252 KB |
Output is correct |
42 |
Correct |
601 ms |
27080 KB |
Output is correct |
43 |
Correct |
592 ms |
27072 KB |
Output is correct |
44 |
Correct |
586 ms |
27492 KB |
Output is correct |
45 |
Correct |
590 ms |
27592 KB |
Output is correct |
46 |
Correct |
332 ms |
21480 KB |
Output is correct |
47 |
Correct |
300 ms |
21136 KB |
Output is correct |
48 |
Correct |
290 ms |
20968 KB |
Output is correct |
49 |
Correct |
222 ms |
17768 KB |
Output is correct |
50 |
Correct |
225 ms |
17808 KB |
Output is correct |
51 |
Correct |
250 ms |
18540 KB |
Output is correct |
52 |
Correct |
240 ms |
18268 KB |
Output is correct |
53 |
Correct |
224 ms |
17832 KB |
Output is correct |
54 |
Correct |
224 ms |
17796 KB |
Output is correct |