Submission #28995

# Submission time Handle Problem Language Result Execution time Memory
28995 2017-07-18T04:18:51 Z nibnalin Dreaming (IOI13_dreaming) C++14
0 / 100
77 ms 15348 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
#include <cassert>
#include "dreaming.h"
using namespace std;

const int maxn = int(1e5)+5, inf = int(2e9)+5;

int n, m, l, D[2][maxn], vis[maxn];
vector<int> cur_comp;
vector<pair<pair<int, int>, int>> guys;
vector<pair<int, int>> graph[maxn];

int dfs(int node, int par, int d, int type)
{
	D[type][node] = d;
	if(type) cur_comp.push_back(node);
	int cur = node;
	for(auto it: graph[node])
	{
		if(it.first != par)
		{
			int tmp = dfs(it.first, node, d+it.second, type);
			if(D[type][cur] < D[type][tmp]) cur = tmp;
		}
	}
	return cur;
}


int travelTime(int _N, int _M, int _L, int _A[], int _B[], int _T[]) {
	n = _N, m = _M, l = _L;
	for(int i = 0;i < m;i++)
	{
		graph[_A[i]].push_back({_B[i], _T[i]});
		graph[_B[i]].push_back({_A[i], _T[i]});
	}

	pair<pair<int, int>, int> prev = {{-1, -1}, -1};
	for(int i = 0;i < n;i++)
	{
		if(!vis[i])
		{
			cur_comp.clear();
			int f1 = dfs(i, -1, 0, 0);
			int f2 = dfs(f1, -1, 0, 0);
			dfs(f2, -1, 0, 1);
			pair<pair<int, int>, int> mini = {{inf, inf}, inf};
			for(auto it: cur_comp)
			{
				mini = min(mini, {{max(D[0][it], D[1][it]), min(D[0][it], D[1][it])}, it});
				vis[it] = 1;
			}
			guys.push_back(mini);
		}
	}
	
	sort(guys.rbegin(), guys.rend());

	for(auto it: guys)
	{
		if(prev.second == -1)
		{
			prev = it;
			continue;
		}

		pair<pair<int, int>, int> t1, t2;
		t1.second = prev.second, t2.second = it.second;
		vector<int> tt1;
		tt1 = {prev.first.first, prev.first.second, it.first.first+l, it.first.second+l};
		sort(tt1.rbegin(), tt1.rend());
		t1.first = {tt1[0], tt1[1]};
		tt1 = {prev.first.first+l, prev.first.second+l, it.first.first, it.first.second};
		sort(tt1.rbegin(), tt1.rend());
		t2.first = {tt1[0], tt1[1]};
		prev = min(t1, t2);
	}

	return prev.first.first+prev.first.second;
}
# Verdict Execution time Memory Grader output
1 Correct 77 ms 15348 KB Output is correct
2 Correct 72 ms 15348 KB Output is correct
3 Correct 57 ms 11124 KB Output is correct
4 Correct 12 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5504 KB Output is correct
7 Incorrect 3 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 15348 KB Output is correct
2 Correct 72 ms 15348 KB Output is correct
3 Correct 57 ms 11124 KB Output is correct
4 Correct 12 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5504 KB Output is correct
7 Incorrect 3 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 15348 KB Output is correct
2 Correct 72 ms 15348 KB Output is correct
3 Correct 57 ms 11124 KB Output is correct
4 Correct 12 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5504 KB Output is correct
7 Incorrect 3 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 7048 KB Output is correct
2 Correct 40 ms 7028 KB Output is correct
3 Correct 44 ms 7032 KB Output is correct
4 Correct 41 ms 7156 KB Output is correct
5 Correct 43 ms 7036 KB Output is correct
6 Correct 46 ms 7996 KB Output is correct
7 Correct 45 ms 7160 KB Output is correct
8 Correct 37 ms 6900 KB Output is correct
9 Correct 40 ms 6908 KB Output is correct
10 Correct 45 ms 7164 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 24 ms 5624 KB Output is correct
13 Correct 24 ms 5624 KB Output is correct
14 Correct 24 ms 5496 KB Output is correct
15 Correct 24 ms 5624 KB Output is correct
16 Correct 25 ms 5496 KB Output is correct
17 Correct 25 ms 5368 KB Output is correct
18 Correct 23 ms 5624 KB Output is correct
19 Correct 25 ms 5496 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Incorrect 3 ms 2688 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 15348 KB Output is correct
2 Correct 72 ms 15348 KB Output is correct
3 Correct 57 ms 11124 KB Output is correct
4 Correct 12 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5504 KB Output is correct
7 Incorrect 3 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 15348 KB Output is correct
2 Correct 72 ms 15348 KB Output is correct
3 Correct 57 ms 11124 KB Output is correct
4 Correct 12 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5504 KB Output is correct
7 Incorrect 3 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -