답안 #543365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
543365 2022-03-30T11:27:26 Z hhhhaura Meetings 2 (JOI21_meetings2) C++14
100 / 100
511 ms 57220 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define ceil(a, b) ((a + b - 1) / (b))
#define all(a) a.begin(), a.end()

using namespace std;

#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)
#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

#ifdef wiwihorz
#define print(a...) cerr << "Line " << __LINE__, kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2>void kout(T1 a, T2 ... e){cerr<<a<<" ",kout(e...);}
#else 
#define print(...) 0
#define vprint(...) 0
#endif
#define x first
#define y second
namespace solver {
	int n, lg;
	vector<vector<int>> mp, ac;
	vector<int> dep, sz, mx, ans;
	void init_(int _n) {
		n = _n;
		lg = 31 - __builtin_clz(n);
		dep.assign(n + 1, 0);
		sz.assign(n + 1, 0);
		ans.assign(n + 1, 0);
		mx.assign(n + 1, 0);
		ac.assign(lg + 1, vector<int>(n + 1, 0));
		mp.assign(n + 1, vector<int>());
	}
	void get_info(int x, int par) {
		sz[x] = 1;
		for(auto i : mp[x]) if(i != par) {
			get_info(i, x);
			sz[x] += sz[i];
			mx[x] = max(mx[x], sz[i]);
		}
	}
	void dfs(int x, int par, int d) {
		dep[x] = d;
		sz[x] = 1;
		ac[0][x] = par;
		for(auto i : mp[x]) if(i != par) {
			dfs(i, x, d + 1);
			sz[x] += sz[i];
		}
	}
	int LCA(int a, int b) {
		if(dep[a] < dep[b]) swap(a, b);
		int need = dep[a] - dep[b];
		rrep(i, 0, lg) if((need >> i) & 1)
			a = ac[i][a];
		if(a == b) return a;
		rrep(i, 0, lg) if(ac[i][a] != ac[i][b]) {
			a = ac[i][a];
			b = ac[i][b];
		}
		return ac[0][a];
	}
	int dis(int a, int b) {
		return dep[a] + dep[b] - 2ll * dep[LCA(a, b)];
	}
	void solve() {
		get_info(1, 1);
		int cen = 1;
		rep(i, 2, n) if(max(mx[i], n - sz[i]) < 
			max(mx[cen], n - sz[cen])) cen = i;
		dfs(cen, cen, 0);
		rep(i, 1, lg) rep(j, 1, n) {
			ac[i][j] = ac[i - 1][ac[i - 1][j]];
		} 
		vector<int> a(n, 0);
		iota(all(a), 1);
		sort(all(a), [&](int a, int b){
			return sz[a] > sz[b];
		});
		int L = cen, R = cen;
		for(auto i : a) if(i != cen) {
			int len = dis(L, R);
			if(dis(L, i) > len) R = i;
			else if(dis(R, i) > len) L = i;
			ans[sz[i]] = max(ans[sz[i]], dis(L, R));
		}
		rrep(i, 1, n - 1) ans[i] = max(ans[i], ans[i + 1]) ;
		rep(i, 1, n) {
			if(i & 1) cout << 1 << "\n";
			else cout << ans[i / 2] + 1 << "\n";
		}
	}
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n; cin >> n;
	init_(n);
	rep(i, 1, n - 1) {
		int a, b;
		cin >> a >> b;
		mp[a].push_back(b);
		mp[b].push_back(a);
	}
	solve();
	return 0;
}

Compilation message

meetings2.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    5 | #pragma loop-opt(on)
      | 
meetings2.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
meetings2.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 3 ms 1108 KB Output is correct
23 Correct 3 ms 1104 KB Output is correct
24 Correct 3 ms 1104 KB Output is correct
25 Correct 3 ms 1108 KB Output is correct
26 Correct 3 ms 1108 KB Output is correct
27 Correct 3 ms 1108 KB Output is correct
28 Correct 3 ms 1108 KB Output is correct
29 Correct 3 ms 1120 KB Output is correct
30 Correct 4 ms 1124 KB Output is correct
31 Correct 3 ms 1108 KB Output is correct
32 Correct 5 ms 1112 KB Output is correct
33 Correct 4 ms 1236 KB Output is correct
34 Correct 3 ms 1112 KB Output is correct
35 Correct 3 ms 1108 KB Output is correct
36 Correct 3 ms 1108 KB Output is correct
37 Correct 2 ms 1108 KB Output is correct
38 Correct 3 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 3 ms 1108 KB Output is correct
23 Correct 3 ms 1104 KB Output is correct
24 Correct 3 ms 1104 KB Output is correct
25 Correct 3 ms 1108 KB Output is correct
26 Correct 3 ms 1108 KB Output is correct
27 Correct 3 ms 1108 KB Output is correct
28 Correct 3 ms 1108 KB Output is correct
29 Correct 3 ms 1120 KB Output is correct
30 Correct 4 ms 1124 KB Output is correct
31 Correct 3 ms 1108 KB Output is correct
32 Correct 5 ms 1112 KB Output is correct
33 Correct 4 ms 1236 KB Output is correct
34 Correct 3 ms 1112 KB Output is correct
35 Correct 3 ms 1108 KB Output is correct
36 Correct 3 ms 1108 KB Output is correct
37 Correct 2 ms 1108 KB Output is correct
38 Correct 3 ms 1108 KB Output is correct
39 Correct 327 ms 49304 KB Output is correct
40 Correct 266 ms 48376 KB Output is correct
41 Correct 332 ms 49320 KB Output is correct
42 Correct 293 ms 50340 KB Output is correct
43 Correct 331 ms 50260 KB Output is correct
44 Correct 291 ms 50256 KB Output is correct
45 Correct 511 ms 54300 KB Output is correct
46 Correct 346 ms 57220 KB Output is correct
47 Correct 266 ms 50224 KB Output is correct
48 Correct 197 ms 50576 KB Output is correct
49 Correct 362 ms 50412 KB Output is correct
50 Correct 188 ms 50608 KB Output is correct
51 Correct 268 ms 56000 KB Output is correct