#include "dreaming.h"
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int NN=1e5;
vector<pair<int,int>> e[NN+10];
bool vis[NN+10];
int dp[NN+10];
int mx[NN+10][2];
void dfs(int x)
{
vis[x]=true;
int mx1=0,mx2=0;
for(auto v:e[x])
{
if(!vis[v.fi])
{
dfs(v.fi);
dp[x]=max(dp[x],dp[v.fi]+v.se);
if(dp[v.fi]+v.se>=mx1)
{
mx2=mx1;
mx1=dp[v.fi]+v.se;
}
else if(dp[v.fi]+v.se>=mx2)
mx2=dp[v.fi]+v.se;
}
}
mx[x][0]=mx1;
mx[x][1]=mx2;
return;
}
void swp(int x,int y,int c)
{
if(mx[x][0]==dp[y])
dp[x]=mx[x][1];
else
dp[x]=mx[x][0];
if(dp[x]+c>=mx[y][0])
{
mx[y][1]=mx[y][0];
mx[y][0]=dp[x]+c;
}
else if(dp[x]+c>mx[y][1])
mx[y][1]=dp[x]+c;
dp[y]=mx[y][0];
return;
}
int dfs2(int x,int p)
{
int ans=dp[x];
for(auto v:e[x])
{
if(v.fi==p)
continue;
swp(x,v.fi,v.se);
ans=min(ans,dfs2(v.fi,x));
swp(v.fi,x,v.se);
}
return ans;
}
int travelTime(int N,int M,int L,int A[],int B[],int T[])
{
for(int i=0;i<M;i++)
{
e[A[i]].emplace_back(B[i],T[i]);
e[B[i]].emplace_back(A[i],T[i]);
}
vector<int> tab={0,0,0};
for(int i=1;i<=N;i++)
{
if(!vis[i])
{
dfs(i);
tab.push_back(dfs2(i,0));
}
}
sort(tab.begin(),tab.end());
reverse(tab.begin(),tab.end());
return max(tab[0]+tab[1]+L,tab[1]+tab[2]+2*L);
}
//int main()
//{
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
// cout.tie(NULL);
// int n,m,l;
// cin>>n>>m>>l;
// vector<int> a(m),b(m),t(m);
// for(int i=0;i<m;i++)
// cin>>a[i]>>b[i]>>t[i];
// cout<<travelTime(n,m,l,a,b,t)<<"\n";
// return 0;
//}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
14304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
14304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
7140 KB |
Output is correct |
2 |
Correct |
25 ms |
7060 KB |
Output is correct |
3 |
Correct |
25 ms |
7084 KB |
Output is correct |
4 |
Correct |
23 ms |
7036 KB |
Output is correct |
5 |
Correct |
37 ms |
7100 KB |
Output is correct |
6 |
Correct |
27 ms |
7332 KB |
Output is correct |
7 |
Correct |
28 ms |
7208 KB |
Output is correct |
8 |
Correct |
26 ms |
7184 KB |
Output is correct |
9 |
Correct |
22 ms |
6940 KB |
Output is correct |
10 |
Correct |
27 ms |
7176 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
6 ms |
4812 KB |
Output is correct |
13 |
Correct |
6 ms |
4808 KB |
Output is correct |
14 |
Correct |
6 ms |
4812 KB |
Output is correct |
15 |
Correct |
6 ms |
4812 KB |
Output is correct |
16 |
Correct |
5 ms |
4812 KB |
Output is correct |
17 |
Correct |
7 ms |
4552 KB |
Output is correct |
18 |
Correct |
8 ms |
4840 KB |
Output is correct |
19 |
Correct |
6 ms |
4816 KB |
Output is correct |
20 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
14304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |