# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
770121 |
2023-06-30T19:18:27 Z |
vjudge1 |
Paths (RMI21_paths) |
C++17 |
|
2 ms |
596 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define vi vector<int>
#define vl vector<long long>
#define vii vector<pair<int,int>>
#define vll vector<pair<long long,long long>>
#define pb push_back
#define ll long long
#define ld long double
#define nl '\n'
#define boost ios::sync_with_stdio(false)
#define mp make_pair
#define se second
#define fi first
#define fore(i, y) for(int i = 0; i < y; i++)
#define forr(i,x,y) for(int i = x;i<=y;i++)
#define forn(i,y,x) for(int i = y; i >= x; i--)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define clr(v,k) memset(v,k,sizeof(v))
#define rall(v) v.rbegin() , v.rend()
#define pii pair<int,int>
#define pll pair<ll , ll>
const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 1;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD)
ll lcm(ll a , ll b) {return a * (b / gcd(a , b));} // least common multiple (PPCM)
// HERE IS THE SOLUTION
vector<vii> adj(20);
vector<bool> used(20 , 0);
vi par(20) , road(20);
ll sum =0;
void dfs(int x , int p)
{
for(auto u : adj[x])
{
if(u.fi == p)continue;
par[u.fi] = x;
road[u.fi] = u.se;
dfs(u.fi , x);
}
}
int main()
{
cin.tie(0);
cout.tie(0);
boost;
freopen("inp.txt" , "r" , stdin);
int n , k;
cin>>n>>k;
fore(i , n - 1)
{
int u , v,c;
cin>>u>>v>>c;
u--;
v--;
adj[u].pb({v,c});
adj[v].pb({u,c});
}
fore(j , n)
{
dfs(j , -1);
ll ans = 0;
fore(mask , (1<<n))
{
if(__builtin_popcount(mask) != k)continue;
sum = 0;
fore(i , n)used[i] = 0;
fore(i , n)
{
if((1<<i) & mask)
{
int l = i;
while(l != j)
{
if(!used[l])
{
sum+=road[l];
used[l] = 1;
}
l = par[l];
}
}
}
ans = max(ans , sum);
}
cout<<ans<<nl;
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:54:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | freopen("inp.txt" , "r" , stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |