답안 #398190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398190 2021-05-03T21:46:10 Z ChrisT Meetings 2 (JOI21_meetings2) C++17
100 / 100
1079 ms 24324 KB
#include <bits/stdc++.h>
using namespace std;
const int MN = 2e5 + 5;
vector<int> adj[MN];
bool vis[MN];
int sz[MN], ans[MN], bit[MN], cent; vector<array<int,2>> toadd;
void update (int i, int v) {
	for (i=MN-i;i<MN;i+=i&-i)
		bit[i] = max(bit[i],v);
}
int query (int i) {
	int ret = -1e9;
	for (i=MN-i;i;i^=i&-i)
		ret = max(ret,bit[i]);
	return ret;
}
void clear (int i) {
	for (i=MN-i;i;i^=i&-i)
		bit[i] = 0;
}
void getsz (int cur, int p = -1) {
	sz[cur] = 1;
	for (int i : adj[cur]) if (!vis[i] && i != p) {
		getsz(i,cur);
		sz[cur] += sz[i];
	}
}
int getcent (int cur, int tot, int p = -1) {
	for (int i : adj[cur]) if (!vis[i] && i != p && sz[i] > tot/2)
		return getcent(i,tot,cur);
	return cur;
}
void dfs (int cur, int ch, int depth = 1, int p = -1) {
	toadd.push_back({sz[cur],depth});
	ans[sz[cur]*2] = max(ans[sz[cur]*2],depth + query(sz[cur]) + 1);
	if (sz[cent] - sz[ch] >= sz[cur]) ans[sz[cur]*2] = max(ans[sz[cur]*2],depth + 1);
	for (int i : adj[cur]) if (i != p && !vis[i]) {
		dfs(i,ch,depth+1,cur);
	}
}
void decomp (int cur) {
	getsz(cur);
	cent = getcent(cur,sz[cur]);
	vis[cent] = 1; getsz(cent);
	for (int i : adj[cent]) if (!vis[i]) {
		dfs(i,i);
		for (auto &[s,d] : toadd) update(s,d);
		toadd.clear();
	}
	for (int i = 1; i <= sz[cent]; i++) clear(i);
	reverse(adj[cent].begin(),adj[cent].end());
	for (int i : adj[cent]) if (!vis[i]) {
		dfs(i,i);
		for (auto &[s,d] : toadd) update(s,d);
		toadd.clear();
	}
	for (int i = 1; i <= sz[cent]; i++) clear(i);
	for (int i : adj[cent]) if (!vis[i]) decomp(i);
}
int main () {
	int n; scanf ("%d",&n);
	for (int i = 1; i < n; i++) {
		int a,b; scanf ("%d %d",&a,&b);
		adj[a].push_back(b); adj[b].push_back(a);
	}
	decomp(1);
	for (int i = n - (n%2); i > 2; i -= 2) ans[i-2] = max(ans[i-2],ans[i]);
	for (int i = 1; i <= n; i++) printf ("%d\n",i&1?1:max(1,ans[i]));
	return 0;
}

Compilation message

meetings2.cpp: In function 'int main()':
meetings2.cpp:61:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |  int n; scanf ("%d",&n);
      |         ~~~~~~^~~~~~~~~
meetings2.cpp:63:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |   int a,b; scanf ("%d %d",&a,&b);
      |            ~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 5020 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 4 ms 4964 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4944 KB Output is correct
18 Correct 4 ms 5068 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 5020 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 4 ms 4964 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4944 KB Output is correct
18 Correct 4 ms 5068 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 8 ms 5248 KB Output is correct
23 Correct 8 ms 5196 KB Output is correct
24 Correct 9 ms 5240 KB Output is correct
25 Correct 10 ms 5240 KB Output is correct
26 Correct 9 ms 5196 KB Output is correct
27 Correct 8 ms 5196 KB Output is correct
28 Correct 9 ms 5200 KB Output is correct
29 Correct 8 ms 5196 KB Output is correct
30 Correct 10 ms 5196 KB Output is correct
31 Correct 9 ms 5176 KB Output is correct
32 Correct 11 ms 5344 KB Output is correct
33 Correct 13 ms 5324 KB Output is correct
34 Correct 6 ms 5196 KB Output is correct
35 Correct 6 ms 5228 KB Output is correct
36 Correct 8 ms 5268 KB Output is correct
37 Correct 7 ms 5196 KB Output is correct
38 Correct 8 ms 5324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 5020 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 4 ms 4964 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4944 KB Output is correct
18 Correct 4 ms 5068 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 8 ms 5248 KB Output is correct
23 Correct 8 ms 5196 KB Output is correct
24 Correct 9 ms 5240 KB Output is correct
25 Correct 10 ms 5240 KB Output is correct
26 Correct 9 ms 5196 KB Output is correct
27 Correct 8 ms 5196 KB Output is correct
28 Correct 9 ms 5200 KB Output is correct
29 Correct 8 ms 5196 KB Output is correct
30 Correct 10 ms 5196 KB Output is correct
31 Correct 9 ms 5176 KB Output is correct
32 Correct 11 ms 5344 KB Output is correct
33 Correct 13 ms 5324 KB Output is correct
34 Correct 6 ms 5196 KB Output is correct
35 Correct 6 ms 5228 KB Output is correct
36 Correct 8 ms 5268 KB Output is correct
37 Correct 7 ms 5196 KB Output is correct
38 Correct 8 ms 5324 KB Output is correct
39 Correct 709 ms 15180 KB Output is correct
40 Correct 728 ms 14768 KB Output is correct
41 Correct 691 ms 15080 KB Output is correct
42 Correct 620 ms 15432 KB Output is correct
43 Correct 668 ms 15156 KB Output is correct
44 Correct 641 ms 15176 KB Output is correct
45 Correct 1079 ms 20164 KB Output is correct
46 Correct 870 ms 24324 KB Output is correct
47 Correct 219 ms 14696 KB Output is correct
48 Correct 200 ms 14920 KB Output is correct
49 Correct 581 ms 15884 KB Output is correct
50 Correct 216 ms 15904 KB Output is correct
51 Correct 525 ms 23264 KB Output is correct