#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector <vector<int>> G(n);
for ( int i = 1; i < n; i++ ){
int u, v; cin >> u >> v;
--u, --v;
G[u].pb(v), G[v].pb(u);
}
vector <vector<int>> s(n, vector <int> (n)), d(n, vector <int> (n));
for ( int i = 0; i < n; i++ ){
auto dfs = [&](auto dfs, int u, int p) -> void{
s[i][u] = 1;
for ( auto &v: G[u] ){
if ( v != p ){
d[i][v] = d[i][u] + 1;
dfs(dfs, v, u);
s[i][u] += s[i][v];
}
}
};
dfs(dfs, i, -1);
}
vector <int> ans(n);
const int S = 1 << n;
for ( int mask = 1; mask < S; mask++ ){
vector <int> a;
for ( int i = 0; i < n; i++ ){
if ( mask >> i & 1 ){
a.pb(i);
}
}
map <int,int> mp;
for ( int rt = 0; rt < n; rt++ ){
int cnt = 0;
for ( auto &u: a ){
cnt += d[rt][u];
} mp[cnt]++;
}
chmax(ans[__builtin_popcount(mask) - 1], mp.begin()->second);
}
for ( auto &i: ans ){
cout << i << ln;
}
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
10 ms |
348 KB |
Output is correct |
5 |
Correct |
12 ms |
464 KB |
Output is correct |
6 |
Correct |
12 ms |
464 KB |
Output is correct |
7 |
Correct |
13 ms |
612 KB |
Output is correct |
8 |
Correct |
27 ms |
348 KB |
Output is correct |
9 |
Correct |
56 ms |
348 KB |
Output is correct |
10 |
Correct |
61 ms |
600 KB |
Output is correct |
11 |
Correct |
54 ms |
348 KB |
Output is correct |
12 |
Correct |
51 ms |
344 KB |
Output is correct |
13 |
Correct |
56 ms |
344 KB |
Output is correct |
14 |
Correct |
13 ms |
344 KB |
Output is correct |
15 |
Correct |
12 ms |
348 KB |
Output is correct |
16 |
Correct |
18 ms |
464 KB |
Output is correct |
17 |
Correct |
26 ms |
344 KB |
Output is correct |
18 |
Correct |
44 ms |
348 KB |
Output is correct |
19 |
Correct |
21 ms |
344 KB |
Output is correct |
20 |
Correct |
45 ms |
436 KB |
Output is correct |
21 |
Correct |
22 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
10 ms |
348 KB |
Output is correct |
5 |
Correct |
12 ms |
464 KB |
Output is correct |
6 |
Correct |
12 ms |
464 KB |
Output is correct |
7 |
Correct |
13 ms |
612 KB |
Output is correct |
8 |
Correct |
27 ms |
348 KB |
Output is correct |
9 |
Correct |
56 ms |
348 KB |
Output is correct |
10 |
Correct |
61 ms |
600 KB |
Output is correct |
11 |
Correct |
54 ms |
348 KB |
Output is correct |
12 |
Correct |
51 ms |
344 KB |
Output is correct |
13 |
Correct |
56 ms |
344 KB |
Output is correct |
14 |
Correct |
13 ms |
344 KB |
Output is correct |
15 |
Correct |
12 ms |
348 KB |
Output is correct |
16 |
Correct |
18 ms |
464 KB |
Output is correct |
17 |
Correct |
26 ms |
344 KB |
Output is correct |
18 |
Correct |
44 ms |
348 KB |
Output is correct |
19 |
Correct |
21 ms |
344 KB |
Output is correct |
20 |
Correct |
45 ms |
436 KB |
Output is correct |
21 |
Correct |
22 ms |
348 KB |
Output is correct |
22 |
Execution timed out |
4035 ms |
249944 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
10 ms |
348 KB |
Output is correct |
5 |
Correct |
12 ms |
464 KB |
Output is correct |
6 |
Correct |
12 ms |
464 KB |
Output is correct |
7 |
Correct |
13 ms |
612 KB |
Output is correct |
8 |
Correct |
27 ms |
348 KB |
Output is correct |
9 |
Correct |
56 ms |
348 KB |
Output is correct |
10 |
Correct |
61 ms |
600 KB |
Output is correct |
11 |
Correct |
54 ms |
348 KB |
Output is correct |
12 |
Correct |
51 ms |
344 KB |
Output is correct |
13 |
Correct |
56 ms |
344 KB |
Output is correct |
14 |
Correct |
13 ms |
344 KB |
Output is correct |
15 |
Correct |
12 ms |
348 KB |
Output is correct |
16 |
Correct |
18 ms |
464 KB |
Output is correct |
17 |
Correct |
26 ms |
344 KB |
Output is correct |
18 |
Correct |
44 ms |
348 KB |
Output is correct |
19 |
Correct |
21 ms |
344 KB |
Output is correct |
20 |
Correct |
45 ms |
436 KB |
Output is correct |
21 |
Correct |
22 ms |
348 KB |
Output is correct |
22 |
Execution timed out |
4035 ms |
249944 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |