답안 #133914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133914 2019-07-21T18:07:35 Z arthurconmy 꿈 (IOI13_dreaming) C++14
32 / 100
70 ms 10488 KB
#include <bits/stdc++.h>
 
#ifndef ARTHUR_LOCAL
	#include "dreaming.h"
#endif
 
using namespace std;
using pii=pair<int,int>;
 
#define ff first
#define ss second
 
const int MAXN = 100001;
vector<pii> adj[MAXN];
bool vis[MAXN];
int dis[MAXN];
pii antipode={-1,-1};
bool vis2[MAXN];
int dis2[MAXN];
pii antipode2={-1,-1};
bool vis3[MAXN];
int semi_diam = -1;
 
void dfs1(int v)
{
	vis[v]=1;
 
	for(auto u_raw:adj[v])
	{
		int u=u_raw.ff;
		int d=u_raw.ss;
 
		if(vis[u]) continue;
		dis[u]=dis[v]+d;
		antipode=max(antipode,{dis[u],u});
		dfs1(u);
	}
}
 
void dfs2(int v)
{
	vis2[v]=1;
 
	for(auto u_raw:adj[v])
	{
		int u=u_raw.ff;
		int d=u_raw.ss;
 
		if(vis2[u]) continue;
		dis2[u]=dis2[v]+d;
		antipode2=max(antipode2,{dis2[u],u});
		dfs2(u);
	}
}
 
void dfs3(int v)
{
	vis3[v]=1;
 
	for(auto u_raw:adj[v])
	{
		int u=u_raw.ff;
		int d=u_raw.ss;
 
		if(vis3[u]) continue;
		semi_diam = min(semi_diam,max(antipode2.ff-dis2[u],dis2[u]));
		dfs3(u);
	}
}
 
int travelTime(int n, int m, int l, int A[], int B[], int T[])
{
	vector<pii> di_sdi; // all the diameter, semi-diameter pairs
 
	for(int i=0; i<m; i++)
	{
		adj[A[i]].push_back(make_pair(B[i],T[i]));
		adj[B[i]].push_back(make_pair(A[i],T[i]));
	}
 
	for(int i=0; i<n; i++)
	{
		if(vis[i]) continue;
 
		dfs1(i);
 
		if(antipode == make_pair(-1,-1))
		{
			di_sdi.push_back({0,0});
			continue;
		}
 
		dfs2(antipode.ss);
 
		// cout << i << " " << antipode.ss << " " << antipode2.ss << " " << antipode2.ff << endl;
 
		semi_diam=int(1e9);
		dfs3(antipode2.ss); // don't think that this need be from antipode2.ss
 
		di_sdi.push_back({semi_diam,antipode2.ff});
 
		antipode={-1,-1};
		antipode2={-1,-1};
	}
 
	// for(auto SD:di_sdi)
	// {
	// 	cout << SD.ff << " " << SD.ss << endl;
	// }
 
	sort(di_sdi.rbegin(),di_sdi.rend());
 
	int ans=0;
 
	for(auto SD:di_sdi) ans=max(ans,SD.ss);
 
	if(di_sdi.size()>=3) ans=max(ans,l+l+di_sdi[1].ff+di_sdi[2].ff);
	if(di_sdi.size()>=2) ans=max(ans,l+di_sdi[0].ff+di_sdi[1].ff);
 
	// cout << ans << endl;
 
	return ans;
}

Compilation message

dreaming.cpp: In function 'void dfs3(int)':
dreaming.cpp:63:7: warning: unused variable 'd' [-Wunused-variable]
   int d=u_raw.ss;
       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 10488 KB Output is correct
2 Correct 68 ms 10488 KB Output is correct
3 Correct 42 ms 7800 KB Output is correct
4 Correct 12 ms 3832 KB Output is correct
5 Correct 11 ms 3448 KB Output is correct
6 Correct 19 ms 4344 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 35 ms 5624 KB Output is correct
9 Correct 43 ms 6648 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 63 ms 7928 KB Output is correct
12 Correct 70 ms 9208 KB Output is correct
13 Correct 6 ms 2812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 10488 KB Output is correct
2 Correct 68 ms 10488 KB Output is correct
3 Correct 42 ms 7800 KB Output is correct
4 Correct 12 ms 3832 KB Output is correct
5 Correct 11 ms 3448 KB Output is correct
6 Correct 19 ms 4344 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 35 ms 5624 KB Output is correct
9 Correct 43 ms 6648 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 63 ms 7928 KB Output is correct
12 Correct 70 ms 9208 KB Output is correct
13 Correct 6 ms 2812 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 5 ms 2680 KB Output is correct
16 Incorrect 4 ms 2684 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 10488 KB Output is correct
2 Correct 68 ms 10488 KB Output is correct
3 Correct 42 ms 7800 KB Output is correct
4 Correct 12 ms 3832 KB Output is correct
5 Correct 11 ms 3448 KB Output is correct
6 Correct 19 ms 4344 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 35 ms 5624 KB Output is correct
9 Correct 43 ms 6648 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 63 ms 7928 KB Output is correct
12 Correct 70 ms 9208 KB Output is correct
13 Correct 6 ms 2812 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 5 ms 2680 KB Output is correct
16 Incorrect 4 ms 2684 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 6692 KB Output is correct
2 Correct 33 ms 6700 KB Output is correct
3 Correct 40 ms 6676 KB Output is correct
4 Correct 34 ms 6644 KB Output is correct
5 Correct 32 ms 6648 KB Output is correct
6 Correct 36 ms 7424 KB Output is correct
7 Correct 32 ms 6772 KB Output is correct
8 Correct 30 ms 6512 KB Output is correct
9 Correct 31 ms 6576 KB Output is correct
10 Correct 35 ms 6764 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 10 ms 4720 KB Output is correct
13 Correct 10 ms 4848 KB Output is correct
14 Correct 10 ms 4760 KB Output is correct
15 Correct 10 ms 4716 KB Output is correct
16 Correct 10 ms 4720 KB Output is correct
17 Correct 9 ms 4336 KB Output is correct
18 Correct 10 ms 4848 KB Output is correct
19 Correct 10 ms 4716 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 4 ms 2808 KB Output is correct
23 Correct 10 ms 4716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 10488 KB Output is correct
2 Correct 68 ms 10488 KB Output is correct
3 Correct 42 ms 7800 KB Output is correct
4 Correct 12 ms 3832 KB Output is correct
5 Correct 11 ms 3448 KB Output is correct
6 Correct 19 ms 4344 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 35 ms 5624 KB Output is correct
9 Correct 43 ms 6648 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 63 ms 7928 KB Output is correct
12 Correct 70 ms 9208 KB Output is correct
13 Correct 6 ms 2812 KB Output is correct
14 Correct 4 ms 2808 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 5 ms 2936 KB Output is correct
17 Correct 4 ms 2808 KB Output is correct
18 Correct 5 ms 2808 KB Output is correct
19 Correct 5 ms 2812 KB Output is correct
20 Correct 4 ms 2808 KB Output is correct
21 Correct 5 ms 2808 KB Output is correct
22 Correct 5 ms 2936 KB Output is correct
23 Correct 4 ms 2680 KB Output is correct
24 Correct 4 ms 2680 KB Output is correct
25 Correct 4 ms 2680 KB Output is correct
26 Incorrect 4 ms 2680 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 10488 KB Output is correct
2 Correct 68 ms 10488 KB Output is correct
3 Correct 42 ms 7800 KB Output is correct
4 Correct 12 ms 3832 KB Output is correct
5 Correct 11 ms 3448 KB Output is correct
6 Correct 19 ms 4344 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 35 ms 5624 KB Output is correct
9 Correct 43 ms 6648 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 63 ms 7928 KB Output is correct
12 Correct 70 ms 9208 KB Output is correct
13 Correct 6 ms 2812 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 5 ms 2680 KB Output is correct
16 Incorrect 4 ms 2684 KB Output isn't correct
17 Halted 0 ms 0 KB -