# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
875835 |
2023-11-20T15:17:11 Z |
Mr_Ph |
Paths (RMI21_paths) |
C++17 |
|
600 ms |
15260 KB |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
ll mod=(ll)1e9+7;
ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
map<pair<int,int>,int>mp;
vector<vi>adj;
int mx=0,lol=0;
vi xd;
void dfs(int node,int parent,int dis,vi path)
{
//cout<<node<<" "<<parent<<endl;
path.push_back(node);
if(adj[node].sz==1)
{
if(dis>mx)
lol=node,mx=dis,xd=path;
}
for(auto i:adj[node])
{
if(i!=parent)
dfs(i,node,dis+mp[{node,i}],path);
}
}
vector<vector<pair<int,int>>>adj1;
int no=0;
int dist[200002];
void dfs1(int node,int parent,int dis)
{
if(dis>=mx)no=node,mx=dis;
for(auto i:adj1[node])
if(i.first!=parent)dfs1(i.first,node,dis+i.second);
}
void dfsdis(int node,int parent,int dis)
{
dist[node]=max(dist[node],dis);
for(auto i:adj1[node])
if(i.first!=parent)dfsdis(i.first,node,dis+i.second);
}
void preprocess() {}
void solve()
{
int n,k;
cin>>n>>k;
adj.resize(n+1);
adj1.resize(n+1);
if(k==1)
{
for(int i=0; i<n-1; i++)
{
int a,b,c;
cin>>a>>b>>c;
adj1[a].push_back({b,c});
adj1[b].push_back({a,c});
}
dfs1(1,0,0);
int xdd=no;
mx=0;
no=0;
dfs1(xdd,0,0);
dfsdis(no,0,0);
dfsdis(xdd,0,0);
for(int i=1;i<=n;i++)
cout<<dist[i]<<" ";
return;
}
for(int i=0; i<n-1; i++)
{
int a,b,c;
cin>>a>>b>>c;
adj[a].push_back(b);
adj[b].push_back(a);
mp[ {a,b}]=c;
mp[ {b,a}]=c;
}
map<pair<int,int>,int>mp1=mp;
for(int root=1; root<=n; root++)
{
mp=mp1;
int x=k;
int ans=0;
while(x--)
{
mx=0,lol=0;
xd.clear();
dfs(root,0,0,{});
if(lol==0)
break;
ans+=mx;
for(int i=1; i<xd.sz; i++)
{
mp[ {xd[i],xd[i-1]}]=0;
mp[ {xd[i-1],xd[i]}]=0;
}
}
cout<<ans<<endl;
}
}
signed main()
{
// freopen("meta_game_input.txt","r",stdin);
// freopen("otput.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
preprocess();
//bla();
int t=1;
//cin>>t;
while(t--)
solve();
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:106:27: 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]
106 | for(int i=1; i<xd.sz; i++)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
61 ms |
512 KB |
Output is correct |
4 |
Correct |
61 ms |
600 KB |
Output is correct |
5 |
Correct |
59 ms |
348 KB |
Output is correct |
6 |
Correct |
42 ms |
344 KB |
Output is correct |
7 |
Correct |
63 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
61 ms |
512 KB |
Output is correct |
4 |
Correct |
61 ms |
600 KB |
Output is correct |
5 |
Correct |
59 ms |
348 KB |
Output is correct |
6 |
Correct |
42 ms |
344 KB |
Output is correct |
7 |
Correct |
63 ms |
344 KB |
Output is correct |
8 |
Execution timed out |
1061 ms |
784 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
61 ms |
512 KB |
Output is correct |
4 |
Correct |
61 ms |
600 KB |
Output is correct |
5 |
Correct |
59 ms |
348 KB |
Output is correct |
6 |
Correct |
42 ms |
344 KB |
Output is correct |
7 |
Correct |
63 ms |
344 KB |
Output is correct |
8 |
Execution timed out |
1061 ms |
784 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
12116 KB |
Output is correct |
2 |
Correct |
55 ms |
15260 KB |
Output is correct |
3 |
Correct |
47 ms |
14120 KB |
Output is correct |
4 |
Correct |
45 ms |
14032 KB |
Output is correct |
5 |
Correct |
53 ms |
14884 KB |
Output is correct |
6 |
Correct |
43 ms |
14028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
61 ms |
512 KB |
Output is correct |
4 |
Correct |
61 ms |
600 KB |
Output is correct |
5 |
Correct |
59 ms |
348 KB |
Output is correct |
6 |
Correct |
42 ms |
344 KB |
Output is correct |
7 |
Correct |
63 ms |
344 KB |
Output is correct |
8 |
Execution timed out |
1061 ms |
784 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |