Submission #893425

# Submission time Handle Problem Language Result Execution time Memory
893425 2023-12-27T04:45:13 Z vjudge1 Meetings 2 (JOI21_meetings2) C++17
4 / 100
4000 ms 132904 KB
#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long

using namespace std;

int pow(int a,int b,int m){int ans=1;while(b){if(b&1){ans=(ans*a)%m;}b>>=1;a=(a*a)%m;}return ans;}
int binpow(int a,int b){int ans=1;while(b){if(b&1){ans=(ans*a);}b>>=1;a=(a*a);}return ans;}
	
const int N = 1e5 + 2, inf = 1e9;

vector <int> g[N];
int timer;
int tin[N], tout[N], up[N][30];
int n, deep[N];
 
void dfs (int v, int p = 0, int d = 0) {
	tin[v] = ++timer;
	up[v][0] = p;
	deep[v] = deep[p] + 1;
	for (int i=1; i<=25; ++i)
		up[v][i] = up[up[v][i-1]][i-1];
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (to != p)
			dfs (to, v, d + 1);
	}
	tout[v] = ++timer;
}
 
bool upper (int a, int b) {
	return tin[a] <= tin[b] && tout[a] >= tout[b];
}

int lca (int a, int b) {
	if(a == b)return a;
	if (upper (a, b))  swap(a, b);
	for (int i=25; i>=0; --i)
		if (! upper (up[a][i], b))
			a = up[a][i];
	return up[a][0];
}
 
int distance(int a, int b){
	int lc = lca(a, b);
	return deep[a] + deep[b] - deep[lc] * 2;
}

main(){
	iostream::sync_with_stdio(false);	
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    for(int i = 0; i < n - 1; i++){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(0, 0);
	for(int i = 1; i <= n; i++){
		int ans = 0;
		for(int bit = 1; bit < (1 << n); bit++){
			if(__builtin_popcount(bit) != i)continue;
			
			vector <int> us, notus;
			//cout <<i <<"->"<< bit << endl;
			for(int j = 0; j < n; j++){
				if(bit & (1 << j)){
					us.pb(j);
				}else
					notus.pb(j);
			}
			vector <int> cnt(n * n, 0);
			for(int x = 0; x < n; x++){
				int sum = 0;
				for(auto y : us){
					sum += distance(x, y);
				}
				cnt[sum]++;
			}
			for(int j = 0; j <= n * n; j++){
				if(cnt[j] > 0){
					ans = max(cnt[j], ans);
					break;
				}
			}
		}
		cout <<  ans << endl;
	}
}

Compilation message

meetings2.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7768 KB Output is correct
2 Correct 2 ms 7768 KB Output is correct
3 Correct 2 ms 7772 KB Output is correct
4 Correct 186 ms 7772 KB Output is correct
5 Correct 186 ms 7772 KB Output is correct
6 Correct 190 ms 7768 KB Output is correct
7 Correct 186 ms 7772 KB Output is correct
8 Correct 431 ms 7772 KB Output is correct
9 Correct 980 ms 7768 KB Output is correct
10 Correct 968 ms 7772 KB Output is correct
11 Correct 969 ms 7772 KB Output is correct
12 Correct 975 ms 7772 KB Output is correct
13 Correct 966 ms 7772 KB Output is correct
14 Correct 190 ms 7772 KB Output is correct
15 Correct 190 ms 7772 KB Output is correct
16 Correct 419 ms 7772 KB Output is correct
17 Correct 935 ms 7772 KB Output is correct
18 Correct 962 ms 7768 KB Output is correct
19 Correct 424 ms 7768 KB Output is correct
20 Correct 973 ms 7772 KB Output is correct
21 Correct 436 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7768 KB Output is correct
2 Correct 2 ms 7768 KB Output is correct
3 Correct 2 ms 7772 KB Output is correct
4 Correct 186 ms 7772 KB Output is correct
5 Correct 186 ms 7772 KB Output is correct
6 Correct 190 ms 7768 KB Output is correct
7 Correct 186 ms 7772 KB Output is correct
8 Correct 431 ms 7772 KB Output is correct
9 Correct 980 ms 7768 KB Output is correct
10 Correct 968 ms 7772 KB Output is correct
11 Correct 969 ms 7772 KB Output is correct
12 Correct 975 ms 7772 KB Output is correct
13 Correct 966 ms 7772 KB Output is correct
14 Correct 190 ms 7772 KB Output is correct
15 Correct 190 ms 7772 KB Output is correct
16 Correct 419 ms 7772 KB Output is correct
17 Correct 935 ms 7772 KB Output is correct
18 Correct 962 ms 7768 KB Output is correct
19 Correct 424 ms 7768 KB Output is correct
20 Correct 973 ms 7772 KB Output is correct
21 Correct 436 ms 8028 KB Output is correct
22 Execution timed out 4035 ms 132904 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7768 KB Output is correct
2 Correct 2 ms 7768 KB Output is correct
3 Correct 2 ms 7772 KB Output is correct
4 Correct 186 ms 7772 KB Output is correct
5 Correct 186 ms 7772 KB Output is correct
6 Correct 190 ms 7768 KB Output is correct
7 Correct 186 ms 7772 KB Output is correct
8 Correct 431 ms 7772 KB Output is correct
9 Correct 980 ms 7768 KB Output is correct
10 Correct 968 ms 7772 KB Output is correct
11 Correct 969 ms 7772 KB Output is correct
12 Correct 975 ms 7772 KB Output is correct
13 Correct 966 ms 7772 KB Output is correct
14 Correct 190 ms 7772 KB Output is correct
15 Correct 190 ms 7772 KB Output is correct
16 Correct 419 ms 7772 KB Output is correct
17 Correct 935 ms 7772 KB Output is correct
18 Correct 962 ms 7768 KB Output is correct
19 Correct 424 ms 7768 KB Output is correct
20 Correct 973 ms 7772 KB Output is correct
21 Correct 436 ms 8028 KB Output is correct
22 Execution timed out 4035 ms 132904 KB Time limit exceeded
23 Halted 0 ms 0 KB -