# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
769995 |
2023-06-30T15:56:38 Z |
vjudge1 |
Paths (RMI21_paths) |
C++17 |
|
600 ms |
10336 KB |
#include <bits/stdc++.h>
#define ve vector
#define vi vector<int>
#define vii vector<ii>
#define ii pair<int,int>
#define fi first
#define se second
#define ll long long
#define INF 1e9+7
#define pb push_back
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>;
const int MOD = 1e9+7;
const int nax = 2e5+5;
void readio(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ve<pair<int,ll>> adj[nax];
bool vis[nax];
ll dfs(int u, int p){
ll mx = 0;
for(auto x : adj[u]){
if(x.fi == p) continue;
if(!vis[x.fi]) mx = max(mx, dfs(x.fi,u)+x.se);
else mx = max(mx, dfs(x.fi, u));
}
//cout << u << " " << mx << endl;
return mx;
}
bool ass(int u, int p, ll path, ll mx){
if(path == mx) return 1;
for(auto x : adj[u]){
if(x.fi == p) continue;
ll cur = path;
if(!vis[x.fi]) cur += x.se;
if(ass(x.fi,u,cur,mx)){
vis[x.fi] = 1;
return 1;
}
}
return 0;
}
int main()
{
optimise;
int n, k;
cin >> n >> k;
for(int i = 0; i < n-1; i++){
int a,b,c;
cin >> a >> b >> c;
a--,b--;
adj[a].pb({b,c});
adj[b].pb({a,c});
}
for (int i = 0; i < n; ++i)
{
ll mx = 0;
memset(vis,0, sizeof vis);
for (int j = 0; j < k; ++j)
{
int cur = dfs(i,i);
mx += cur;
ass(i,i, 0, cur);
}
cout << mx << endl;
}
}
Compilation message
Main.cpp: In function 'void readio()':
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1052 ms |
10336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |