Submission #396574

# Submission time Handle Problem Language Result Execution time Memory
396574 2021-04-30T10:24:42 Z Jasiekstrz Dreaming (IOI13_dreaming) C++17
18 / 100
64 ms 15540 KB
#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];
int dfs(int x)
{
	int ans=0;
	vis[x]=true;
	int mx1=0,mx2=0;
	for(auto v:e[x])
	{
		if(!vis[v.fi])
		{
			ans=max(ans,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 max(ans,mx1+mx2);
}
void swp(int x,int y,int c)
{
	if(mx[x][0]==dp[y]+c)
		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;
	int ans=0;
	for(int i=1;i<=N;i++)
	{
		if(!vis[i])
		{
			ans=max(ans,dfs(i));
			tab.push_back(dfs2(i,0));
		}
	}
	sort(tab.begin(),tab.end());
	reverse(tab.begin(),tab.end());
	if(tab.size()==1)
		return max(ans,tab[0]);
	else if(tab.size()==2)
		return max(ans,tab[0]+tab[1]+L);
	return max({ans,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;
//}

# Verdict Execution time Memory Grader output
1 Correct 64 ms 13252 KB Output is correct
2 Correct 53 ms 15540 KB Output is correct
3 Correct 34 ms 9716 KB Output is correct
4 Correct 9 ms 4272 KB Output is correct
5 Correct 7 ms 3532 KB Output is correct
6 Correct 14 ms 5464 KB Output is correct
7 Incorrect 2 ms 2640 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2592 KB Output is correct
3 Incorrect 2 ms 2656 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 64 ms 13252 KB Output is correct
2 Correct 53 ms 15540 KB Output is correct
3 Correct 34 ms 9716 KB Output is correct
4 Correct 9 ms 4272 KB Output is correct
5 Correct 7 ms 3532 KB Output is correct
6 Correct 14 ms 5464 KB Output is correct
7 Incorrect 2 ms 2640 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 6608 KB Output is correct
2 Correct 26 ms 6684 KB Output is correct
3 Correct 30 ms 6588 KB Output is correct
4 Correct 26 ms 6680 KB Output is correct
5 Correct 30 ms 6584 KB Output is correct
6 Correct 28 ms 7144 KB Output is correct
7 Correct 25 ms 6864 KB Output is correct
8 Correct 23 ms 6528 KB Output is correct
9 Correct 31 ms 6508 KB Output is correct
10 Correct 27 ms 6776 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 6 ms 4552 KB Output is correct
13 Correct 7 ms 4552 KB Output is correct
14 Correct 8 ms 4424 KB Output is correct
15 Correct 6 ms 4424 KB Output is correct
16 Correct 6 ms 4424 KB Output is correct
17 Correct 6 ms 4168 KB Output is correct
18 Correct 7 ms 4552 KB Output is correct
19 Correct 6 ms 4424 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 6 ms 4424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2592 KB Output is correct
3 Incorrect 2 ms 2656 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 64 ms 13252 KB Output is correct
2 Correct 53 ms 15540 KB Output is correct
3 Correct 34 ms 9716 KB Output is correct
4 Correct 9 ms 4272 KB Output is correct
5 Correct 7 ms 3532 KB Output is correct
6 Correct 14 ms 5464 KB Output is correct
7 Incorrect 2 ms 2640 KB Output isn't correct
8 Halted 0 ms 0 KB -