# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
122267 |
2019-06-28T03:15:37 Z |
Retro3014 |
None (JOI16_ho_t3) |
C++17 |
|
274 ms |
23900 KB |
#include <bits/stdc++.h>
#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 2000000000
#define INFLL 1000000000000000000LL
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX_N = 100000;
int N, M, Q;
vector<pair<pii, int> > edge;
vector<pii> gp[MAX_N+1];
int dist[MAX_N+1];
vector<pair<int, pii> > edge2;
priority_queue<pii, vector<pii>, greater<pii> > pq;
void dijk(){
pq.push({0, 1});
while(!pq.empty()){
int now = pq.top().second; pq.pop();
for(int i=0; i<gp[now].size(); i++){
if(gp[now][i].first==1) continue;
if(dist[gp[now][i].first] == 0 || dist[gp[now][i].first]==dist[now]+1){
if(dist[gp[now][i].first]==0){
dist[gp[now][i].first] = dist[now]+1;
pq.push({dist[gp[now][i].first], gp[now][i].first});
}
edge2.pb({gp[now][i].second, {now, gp[now][i].first}});
}
}
}
}
int group[MAX_N+1], num[MAX_N+1];
void init_g(){
for(int i=1; i<=N; i++){
group[i] = i; num[i] = 1;
}
}
int find_g(int x){
return (x==group[x])? x : group[x] = find_g(group[x]);
}
void union_g(int x, int y){
x = find_g(x); y = find_g(y);
if(x==y) return;
group[x] = y;
num[y]+=num[x];
}
vector<int> ans;
int cnt = 1;
vector<int> gp2[MAX_N+1];
bool chk[MAX_N+1];
void dfs(int x){
if(chk[x]) return;
chk[x] = true; cnt++;
for(int i=0; i<gp2[x].size(); i++){
dfs(gp2[x][i]);
}
}
void add(int x, int y){
gp2[x].pb(y);
//cout<<x<<" "<<y<<endl;
//cout<<chk[x]<<" "<<chk[y]<<endl;
if(chk[x]){
if(chk[y]) return;
dfs(y);
}
}
int main(){
scanf("%d%d%d", &N, &M, &Q);
for(int i=1; i<=M; i++){
int a, b;
scanf("%d%d", &a, &b);
edge.pb({{a, b}, Q+1});
}
for(int i=1; i<=Q; i++){
int x;
scanf("%d", &x);
edge[x-1].second = i;
}
for(int i=0; i<edge.size(); i++){
gp[edge[i].first.first].pb({edge[i].first.second, edge[i].second});
gp[edge[i].first.second].pb({edge[i].first.first, edge[i].second});
}
dijk();
sort(edge2.begin(), edge2.end());
/*for(int i=0; i<edge2.size(); i++){
printf("%d %d\n", edge2[i].second.first, edge2[i].second.second);
}*/
//init_g();
chk[1] = true;
for(int i=Q; i>=1; i--){
//cout<<i<<endl;
while(!edge2.empty() && edge2.back().first>i){
add(edge2.back().second.first, edge2.back().second.second);
edge2.pop_back();
}
ans.pb(N-cnt);
}
while(!ans.empty()){
printf("%d\n", ans.back());
ans.pop_back();
}
return 0;
}
Compilation message
2016_ho_t3.cpp: In function 'void dijk()':
2016_ho_t3.cpp:38:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<gp[now].size(); i++){
~^~~~~~~~~~~~~~~
2016_ho_t3.cpp: In function 'void dfs(int)':
2016_ho_t3.cpp:79:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<gp2[x].size(); i++){
~^~~~~~~~~~~~~~
2016_ho_t3.cpp: In function 'int main()':
2016_ho_t3.cpp:106:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<edge.size(); i++){
~^~~~~~~~~~~~
2016_ho_t3.cpp:95:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &N, &M, &Q);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
2016_ho_t3.cpp:98:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a, &b);
~~~~~^~~~~~~~~~~~~~~~
2016_ho_t3.cpp:103:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &x);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5248 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
4992 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5248 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
4992 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
162 ms |
21392 KB |
Output is correct |
10 |
Correct |
177 ms |
21476 KB |
Output is correct |
11 |
Correct |
138 ms |
20680 KB |
Output is correct |
12 |
Correct |
157 ms |
20704 KB |
Output is correct |
13 |
Correct |
177 ms |
20964 KB |
Output is correct |
14 |
Correct |
161 ms |
21976 KB |
Output is correct |
15 |
Correct |
85 ms |
16372 KB |
Output is correct |
16 |
Correct |
77 ms |
18412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
161 ms |
19028 KB |
Output is correct |
2 |
Correct |
165 ms |
21348 KB |
Output is correct |
3 |
Correct |
122 ms |
17632 KB |
Output is correct |
4 |
Correct |
146 ms |
20796 KB |
Output is correct |
5 |
Correct |
159 ms |
22104 KB |
Output is correct |
6 |
Correct |
171 ms |
21952 KB |
Output is correct |
7 |
Correct |
83 ms |
18408 KB |
Output is correct |
8 |
Correct |
79 ms |
18404 KB |
Output is correct |
9 |
Correct |
68 ms |
13288 KB |
Output is correct |
10 |
Correct |
69 ms |
13672 KB |
Output is correct |
11 |
Correct |
193 ms |
20848 KB |
Output is correct |
12 |
Correct |
167 ms |
20320 KB |
Output is correct |
13 |
Correct |
166 ms |
20192 KB |
Output is correct |
14 |
Correct |
183 ms |
21092 KB |
Output is correct |
15 |
Correct |
208 ms |
22276 KB |
Output is correct |
16 |
Correct |
197 ms |
22240 KB |
Output is correct |
17 |
Correct |
206 ms |
22884 KB |
Output is correct |
18 |
Correct |
134 ms |
19940 KB |
Output is correct |
19 |
Correct |
274 ms |
23900 KB |
Output is correct |
20 |
Correct |
171 ms |
22884 KB |
Output is correct |
21 |
Correct |
107 ms |
17636 KB |
Output is correct |
22 |
Correct |
156 ms |
17636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5248 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
4992 KB |
Output is correct |
7 |
Correct |
6 ms |
4992 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
162 ms |
21392 KB |
Output is correct |
10 |
Correct |
177 ms |
21476 KB |
Output is correct |
11 |
Correct |
138 ms |
20680 KB |
Output is correct |
12 |
Correct |
157 ms |
20704 KB |
Output is correct |
13 |
Correct |
177 ms |
20964 KB |
Output is correct |
14 |
Correct |
161 ms |
21976 KB |
Output is correct |
15 |
Correct |
85 ms |
16372 KB |
Output is correct |
16 |
Correct |
77 ms |
18412 KB |
Output is correct |
17 |
Correct |
161 ms |
19028 KB |
Output is correct |
18 |
Correct |
165 ms |
21348 KB |
Output is correct |
19 |
Correct |
122 ms |
17632 KB |
Output is correct |
20 |
Correct |
146 ms |
20796 KB |
Output is correct |
21 |
Correct |
159 ms |
22104 KB |
Output is correct |
22 |
Correct |
171 ms |
21952 KB |
Output is correct |
23 |
Correct |
83 ms |
18408 KB |
Output is correct |
24 |
Correct |
79 ms |
18404 KB |
Output is correct |
25 |
Correct |
68 ms |
13288 KB |
Output is correct |
26 |
Correct |
69 ms |
13672 KB |
Output is correct |
27 |
Correct |
193 ms |
20848 KB |
Output is correct |
28 |
Correct |
167 ms |
20320 KB |
Output is correct |
29 |
Correct |
166 ms |
20192 KB |
Output is correct |
30 |
Correct |
183 ms |
21092 KB |
Output is correct |
31 |
Correct |
208 ms |
22276 KB |
Output is correct |
32 |
Correct |
197 ms |
22240 KB |
Output is correct |
33 |
Correct |
206 ms |
22884 KB |
Output is correct |
34 |
Correct |
134 ms |
19940 KB |
Output is correct |
35 |
Correct |
274 ms |
23900 KB |
Output is correct |
36 |
Correct |
171 ms |
22884 KB |
Output is correct |
37 |
Correct |
107 ms |
17636 KB |
Output is correct |
38 |
Correct |
156 ms |
17636 KB |
Output is correct |
39 |
Correct |
251 ms |
23872 KB |
Output is correct |
40 |
Correct |
251 ms |
23808 KB |
Output is correct |
41 |
Correct |
161 ms |
19552 KB |
Output is correct |
42 |
Correct |
236 ms |
23140 KB |
Output is correct |
43 |
Correct |
208 ms |
23000 KB |
Output is correct |
44 |
Correct |
195 ms |
23664 KB |
Output is correct |
45 |
Correct |
191 ms |
23644 KB |
Output is correct |
46 |
Correct |
126 ms |
18184 KB |
Output is correct |
47 |
Correct |
98 ms |
16912 KB |
Output is correct |
48 |
Correct |
93 ms |
16876 KB |
Output is correct |
49 |
Correct |
96 ms |
14380 KB |
Output is correct |
50 |
Correct |
91 ms |
14408 KB |
Output is correct |
51 |
Correct |
101 ms |
15336 KB |
Output is correct |
52 |
Correct |
94 ms |
14996 KB |
Output is correct |
53 |
Correct |
85 ms |
14132 KB |
Output is correct |
54 |
Correct |
96 ms |
14512 KB |
Output is correct |