# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
994433 |
2024-06-07T15:44:54 Z |
De3b0o |
Paths (RMI21_paths) |
C++14 |
|
46 ms |
15720 KB |
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*n)
#define rc (2*n+1)
using namespace std;
ll fp(ll x , ll y)
{
if(y==0)
return 1;
ll z = fp(x,y/2);
if(y&1)
return z*z*x;
else
return z*z;
}
int sqrot(ll x)
{
int l = 0 , r = INT_MAX;
while(l<=r)
{
if(mid*mid>=x)
r=mid-1;
else
l=mid+1;
}
return r+1;
}
ll cel(ll x , ll y)
{
return x/y + bool(x%y);
}
string tb(ll x)
{
string s = "";
while(x>0)
{
if(x&1)
s+='1';
else
s+='0';
x/=2;
}
while(s.size()<60)
s+='0';
return s;
}
ll fb(string s)
{
ll x = 0;
ll c = 1;
for(int8_t i = 0 ; 60>i ; i++)
{
if(s[i]=='1')
x+=c;
c*=2;
}
return x;
}
ll n , k;
vector<pll> adj[100009];
ll mx1[100009] , mx2[100009] , c1[100009] , c2[100009];
void dpt1(ll x , ll p)
{
for(auto it : adj[x])
{
if(it.F==p)
continue;
dpt1(it.F,x);
if(mx1[it.F]+it.S>mx1[x])
{
mx2[x]=mx1[x];
c2[x]=c1[x];
mx1[x]=mx1[it.F]+it.S;
c1[x]=it.F;
}
else if(mx1[it.F]+it.S>mx2[x])
{
mx2[x]=mx1[it.F]+it.S;
c2[x]=it.F;
}
}
}
void dpt2(ll x , ll p , ll c)
{
if(x!=1)
{
ll y = c;
if(c1[p]!=x)
y+=mx1[p];
else
y+=mx2[p];
if(y>mx1[x])
{
mx2[x]=mx1[x];
c2[x]=c1[x];
mx1[x]=y;
c1[x]=p;
}
else if(y>mx2[x])
{
mx2[x]=y;
c2[x]=p;
}
}
for(auto it : adj[x])
{
if(it.F!=p)
dpt2(it.F,x,it.S);
}
}
int main()
{
d3
cin >> n >> k;
for(int i = 0 ; n-1>i ; i++)
{
ll x , y , c;
cin >> x >> y >> c;
adj[x].pb({y,c});
adj[y].pb({x,c});
}
dpt1(1,0);
dpt2(1,0,0);
for(int i = 1 ; n>=i ; i++)
cout << mx1[i] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
5724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
5724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
5724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
5724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
14160 KB |
Output is correct |
2 |
Correct |
42 ms |
15720 KB |
Output is correct |
3 |
Correct |
38 ms |
14196 KB |
Output is correct |
4 |
Correct |
40 ms |
14032 KB |
Output is correct |
5 |
Correct |
46 ms |
14940 KB |
Output is correct |
6 |
Correct |
40 ms |
14028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
5724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |