#include<bits/stdc++.h>
#define int long long
#define ll pair<int,int>
using namespace std;
const int N=200022;
vector<int> ke[N];
int oo=1e18;
int d[20][20];
int kq[N];
int D[20];
void dfs(int u,int pa,int dist,int dinh)
{
d[dinh][u]=dist;
//cout << dinh << " " << u << " " << dist << '\n';
for (int i=0;i<ke[u].size();i++)
{
int v=ke[u][i];
if (v==pa) continue;
dfs(v,u,dist+1,dinh);
}
}
signed main()
{
// freopen("kk.inp","r",stdin);
// freopen("kk.out","w",stdout);
// freopen("BETTER.INP","r",stdin);
// freopen("BETTER.OUT","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int kt=0;
for (int i=1;i<n;i++)
{
int u,v;
cin >> u >> v;
ke[u].push_back(v);
ke[v].push_back(u);
if ((u!=i) or (v!=i+1))
{
kt=-1;
}
}
if (kt==0)
{
for (int i=1;i<=n;i++)
{
if (i%2==1) cout << 1 << '\n';
else cout << n-(i-2) << '\n';
}
return 0;
}
for (int i=1;i<=n;i++)
{
dfs(i,0,0,i);
}
for (int mask=0;mask<(1<<n);mask++)
{
for (int i=1;i<=n;i++) D[i]=0;
int dem=0;
for (int i=1;i<=n;i++)
{
int kk=((mask>>(i-1))&1);
if (kk)
{
dem++;
for (int i2=1;i2<=n;i2++)
{
D[i2]+=d[i][i2];
}
}
}
int minn=oo;
int cnt=0;
for (int i=1;i<=n;i++)
{
if (minn>D[i])
{
minn=D[i];
cnt=0;
}
if (minn==D[i]) cnt++;
}
kq[dem]=max(kq[dem],cnt);
//cout << mask << ' ' << cnt << " " << minn << '\n';
}
for (int i=1;i<=n;i++) cout << kq[i] << '\n';
}
Compilation message
timeleap.cpp: In function 'void dfs(long long int, long long int, long long int, long long int)':
timeleap.cpp:17:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i=0;i<ke[u].size();i++)
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
12892 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
12892 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
12892 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |