Submission #893425

#TimeUsernameProblemLanguageResultExecution timeMemory
893425vjudge1Meetings 2 (JOI21_meetings2)C++17
4 / 100
4035 ms132904 KiB
#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 (stderr)

meetings2.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...