This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
bool dfs(int st, vector<array<int,2>>(&g)[],int dis, int mas, int k, int p){
bool work = 1;
if((1<<st)&mas)
dis=0;
for(array<int,2>node : g[st]){
if(node[0]==p)
continue;
work&=dfs(node[0],g,dis+node[1],mas,k,st);
}
if(dis>=k){
return 0;
}
return work;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,k;
cin >> n >> k;
vector<array<int,2>>g[n];
bool cas1 = 1;
for(int i = 0;i<n-1;i++){
int a,b,d;
cin >> a >> b >> d;
a--;b--;
g[a].push_back({b,d});
g[b].push_back({a,d});
if(d<=k){
cas1=0;
}
}
if(cas1){
cout << n << "\n";
for(int i = 1;i<=n;i++){
cout << i << " ";
}
return 0;
}
return 0;
if(n<=17){
int mx=(1<<n)-1;
for(int mask = 1;mask<(1<<n);mask++){
for(int i = 0;i<n;i++){
if(mask&(1<<i)){
if(dfs(i,g,0,mask,k,-1)){
if(__builtin_popcount(mask)<=__builtin_popcount(mx)){
mx=mask;
}
}
break;
}
}
}
cout << __builtin_popcount(mx) << "\n";
for(int i = 0;i<n;i++){
if((1<<i)&mx){
cout << i+1 << " ";
}
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |