답안 #396629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
396629 2021-04-30T13:27:52 Z Jasiekstrz 꿈 (IOI13_dreaming) C++17
18 / 100
53 ms 15044 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,bool xd)
{
	if(mx[x][0]==dp[y]+c)
		dp[x]=mx[x][1];
	else
		dp[x]=mx[x][0];
	if(xd)
	{
		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,1);
		ans=min(ans,dfs2(v.fi,x));
		swp(v.fi,x,v.se,0);
	}
	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;
//}

# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 14276 KB Output is correct
2 Correct 53 ms 15044 KB Output is correct
3 Correct 34 ms 9572 KB Output is correct
4 Correct 9 ms 4216 KB Output is correct
5 Correct 7 ms 3564 KB Output is correct
6 Correct 14 ms 5480 KB Output is correct
7 Incorrect 3 ms 2656 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Incorrect 2 ms 2636 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 14276 KB Output is correct
2 Correct 53 ms 15044 KB Output is correct
3 Correct 34 ms 9572 KB Output is correct
4 Correct 9 ms 4216 KB Output is correct
5 Correct 7 ms 3564 KB Output is correct
6 Correct 14 ms 5480 KB Output is correct
7 Incorrect 3 ms 2656 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 6936 KB Output is correct
2 Correct 23 ms 6992 KB Output is correct
3 Correct 24 ms 6964 KB Output is correct
4 Correct 24 ms 6964 KB Output is correct
5 Correct 23 ms 6988 KB Output is correct
6 Correct 24 ms 7388 KB Output is correct
7 Correct 29 ms 7088 KB Output is correct
8 Correct 25 ms 6916 KB Output is correct
9 Correct 23 ms 6860 KB Output is correct
10 Correct 24 ms 7112 KB Output is correct
11 Correct 2 ms 2656 KB Output is correct
12 Correct 5 ms 4552 KB Output is correct
13 Correct 6 ms 4552 KB Output is correct
14 Correct 6 ms 4448 KB Output is correct
15 Correct 5 ms 4552 KB Output is correct
16 Correct 6 ms 4424 KB Output is correct
17 Correct 5 ms 4168 KB Output is correct
18 Correct 6 ms 4552 KB Output is correct
19 Correct 5 ms 4448 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 5 ms 4424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Incorrect 2 ms 2636 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 14276 KB Output is correct
2 Correct 53 ms 15044 KB Output is correct
3 Correct 34 ms 9572 KB Output is correct
4 Correct 9 ms 4216 KB Output is correct
5 Correct 7 ms 3564 KB Output is correct
6 Correct 14 ms 5480 KB Output is correct
7 Incorrect 3 ms 2656 KB Output isn't correct
8 Halted 0 ms 0 KB -