Submission #133917

# Submission time Handle Problem Language Result Execution time Memory
133917 2019-07-21T18:18:25 Z arthurconmy Dreaming (IOI13_dreaming) C++14
32 / 100
90 ms 12536 KB
#include <bits/stdc++.h>

#ifndef ARTHUR_LOCAL
	#include "dreaming.h"
#endif

using namespace std;
using pii=pair<int,int>;
using vi=vector<int>;
using ll = long long;

#define ff first
#define ss second

const int MAXN = 100001;

vector<pair<int,ll>> adj[MAXN];

bool vis[MAXN];
ll dis[MAXN];
pair<ll,int> antipode={ll(-1),-1};

bool vis2[MAXN];
ll dis2[MAXN];
pair<ll,int> antipode2={ll(-1),-1};

bool vis3[MAXN];
ll semi_diam = -1;

void dfs1(int v)
{
	vis[v]=1;

	for(auto u_raw:adj[v])
	{
		int u=u_raw.ff;
		ll 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;
		ll 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;

		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<pair<ll,ll>> di_sdi; // all the diameter, semi-diameter pairs

	for(int i=0; i<m; i++)
	{
		adj[A[i]].push_back(make_pair(B[i],ll(T[i])));
		adj[B[i]].push_back(make_pair(A[i],ll(T[i])));
	}

	for(int i=0; i<n; i++)
	{
		if(vis[i]) continue;

		dfs1(i);

		if(antipode == make_pair(ll(-1),-1))
		{
			di_sdi.push_back({0,0});
			continue;
		}

		dfs2(antipode.ss);

		semi_diam=max(antipode2.ff-dis[antipode2.ss],dis[antipode2.ss]);
		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());

	ll ans=0;

	for(auto SD:di_sdi) ans=max(ans,SD.ss);
	if(di_sdi.size()>=3) ans=max(ans,ll(l + l) + di_sdi[1].ff + di_sdi[2].ff);
	if(di_sdi.size()>=2) ans=max(ans,ll(l) + di_sdi[0].ff + di_sdi[1].ff);

	// cout << ans << endl;

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 64 ms 12536 KB Output is correct
2 Correct 71 ms 12536 KB Output is correct
3 Correct 45 ms 9080 KB Output is correct
4 Correct 13 ms 4216 KB Output is correct
5 Correct 11 ms 3704 KB Output is correct
6 Correct 20 ms 5112 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 36 ms 6776 KB Output is correct
9 Correct 47 ms 8048 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 69 ms 9976 KB Output is correct
12 Correct 90 ms 11512 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 12536 KB Output is correct
2 Correct 71 ms 12536 KB Output is correct
3 Correct 45 ms 9080 KB Output is correct
4 Correct 13 ms 4216 KB Output is correct
5 Correct 11 ms 3704 KB Output is correct
6 Correct 20 ms 5112 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 36 ms 6776 KB Output is correct
9 Correct 47 ms 8048 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 69 ms 9976 KB Output is correct
12 Correct 90 ms 11512 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
14 Correct 4 ms 2684 KB Output is correct
15 Correct 4 ms 2684 KB Output is correct
16 Incorrect 5 ms 2680 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 64 ms 12536 KB Output is correct
2 Correct 71 ms 12536 KB Output is correct
3 Correct 45 ms 9080 KB Output is correct
4 Correct 13 ms 4216 KB Output is correct
5 Correct 11 ms 3704 KB Output is correct
6 Correct 20 ms 5112 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 36 ms 6776 KB Output is correct
9 Correct 47 ms 8048 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 69 ms 9976 KB Output is correct
12 Correct 90 ms 11512 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
14 Correct 4 ms 2684 KB Output is correct
15 Correct 4 ms 2684 KB Output is correct
16 Incorrect 5 ms 2680 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 7888 KB Output is correct
2 Correct 32 ms 7920 KB Output is correct
3 Correct 44 ms 7788 KB Output is correct
4 Correct 36 ms 7920 KB Output is correct
5 Correct 35 ms 7920 KB Output is correct
6 Correct 39 ms 9200 KB Output is correct
7 Correct 35 ms 8044 KB Output is correct
8 Correct 33 ms 7792 KB Output is correct
9 Correct 33 ms 7784 KB Output is correct
10 Correct 35 ms 8044 KB Output is correct
11 Correct 4 ms 2684 KB Output is correct
12 Correct 12 ms 6128 KB Output is correct
13 Correct 12 ms 6380 KB Output is correct
14 Correct 12 ms 6124 KB Output is correct
15 Correct 12 ms 6124 KB Output is correct
16 Correct 12 ms 5996 KB Output is correct
17 Correct 11 ms 5356 KB Output is correct
18 Correct 12 ms 6376 KB Output is correct
19 Correct 12 ms 5996 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2612 KB Output is correct
22 Correct 4 ms 2808 KB Output is correct
23 Correct 11 ms 5992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 12536 KB Output is correct
2 Correct 71 ms 12536 KB Output is correct
3 Correct 45 ms 9080 KB Output is correct
4 Correct 13 ms 4216 KB Output is correct
5 Correct 11 ms 3704 KB Output is correct
6 Correct 20 ms 5112 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 36 ms 6776 KB Output is correct
9 Correct 47 ms 8048 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 69 ms 9976 KB Output is correct
12 Correct 90 ms 11512 KB Output is correct
13 Correct 4 ms 2808 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 2936 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 2652 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 64 ms 12536 KB Output is correct
2 Correct 71 ms 12536 KB Output is correct
3 Correct 45 ms 9080 KB Output is correct
4 Correct 13 ms 4216 KB Output is correct
5 Correct 11 ms 3704 KB Output is correct
6 Correct 20 ms 5112 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 36 ms 6776 KB Output is correct
9 Correct 47 ms 8048 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 69 ms 9976 KB Output is correct
12 Correct 90 ms 11512 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
14 Correct 4 ms 2684 KB Output is correct
15 Correct 4 ms 2684 KB Output is correct
16 Incorrect 5 ms 2680 KB Output isn't correct
17 Halted 0 ms 0 KB -