답안 #396558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
396558 2021-04-30T09:52:54 Z Jasiekstrz 꿈 (IOI13_dreaming) C++17
18 / 100
52 ms 13128 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];
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]+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;
	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());
	if(tab.size()==1)
		return tab[0];
	else if(tab.size()==2)
		return tab[0]+tab[1]+L;
	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 52 ms 13128 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 52 ms 13128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 6480 KB Output is correct
2 Correct 31 ms 6468 KB Output is correct
3 Correct 25 ms 6480 KB Output is correct
4 Correct 23 ms 6576 KB Output is correct
5 Correct 24 ms 6528 KB Output is correct
6 Correct 25 ms 7016 KB Output is correct
7 Correct 24 ms 6636 KB Output is correct
8 Correct 22 ms 6512 KB Output is correct
9 Correct 24 ms 6464 KB Output is correct
10 Correct 24 ms 6676 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 6 ms 4552 KB Output is correct
13 Correct 6 ms 4552 KB Output is correct
14 Correct 6 ms 4424 KB Output is correct
15 Correct 5 ms 4424 KB Output is correct
16 Correct 6 ms 4480 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 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
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 52 ms 13128 KB Output isn't correct
2 Halted 0 ms 0 KB -