Submission #90159

# Submission time Handle Problem Language Result Execution time Memory
90159 2018-12-20T16:50:59 Z FiloSanza Dreaming (IOI13_dreaming) C++14
47 / 100
1000 ms 8796 KB
#include "dreaming.h"
#include <bits/stdc++.h>

const int INF = 2e9;

using namespace std;

struct arco
{
	int to, p;
};
int N;
vector<vector<arco>> g;
vector<int> dist;
vector<int> padre;
vector<pair<int, int>> centers;
vector<int> temp;

int bfs(int node, bool precalcolo){
	queue<int> q;
	dist[node] = 0;
	q.push(node);

	for(int i=0; i<N; i++)
		padre[i] = i;

	int maxiNode = node;
	int maxi = 0;
	while(!q.empty()){
		auto curr = q.front();
		q.pop();

		if(maxi < dist[curr])
			maxi = dist[curr], maxiNode = curr;

		for(auto i : g[curr]){
			if(dist[i.to] > dist[curr] + i.p){
				padre[i.to] = curr;
				q.push(i.to);
				dist[i.to] = dist[curr] + i.p;
			}
		}
	}

	// for(auto i : padre)cout << i << " ";
		// cout << "\n\n";
	if(precalcolo)
		temp.push_back(maxiNode);
	else{
		int diameter = maxi;
		int center = maxiNode;
		int curr = maxiNode;
		maxi = maxi;
		// cout << curr <<"\n";
		// cout << "\t" << max(diameter-dist[curr], dist[curr]) << " " << maxi << "\n";
		while(padre[curr] != curr){
			//cout << curr << " " << padre[curr] << "\n";
			curr = padre[curr];
			//cout << curr << "\n";
			if(max(diameter-dist[curr], dist[curr]) < maxi){
				//cout << "\t" << max(diameter-dist[curr], dist[curr]) << " " << maxi << "\n";
				maxi = max(diameter-dist[curr], dist[curr]);
				center = curr;
			}
		}

		centers.push_back({maxi, center});
	}

	return *max_element(dist.begin(), dist.end());
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	::N = N;
    g.resize(N);
    dist.resize(N);
    padre.resize(N);

    for(int i=0; i<M; i++){
    	g[A[i]].push_back({B[i], T[i]});
    	g[B[i]].push_back({A[i], T[i]});
    }

	fill(dist.begin(), dist.end(), INF);
    for(int i=0; i<N; i++) if(dist[i] == INF)
    	bfs(i, true);

	fill(dist.begin(), dist.end(), INF);
    for(auto i : temp)
    	bfs(i, false);

    sort(centers.begin(), centers.end());

    for(int i=0; i<centers.size()-1; i++){
    	// cout << "Aggiungo gli archi " << centers[i].second << " " << centers[centers.size()-1].second << "\n";
    	g[centers[i].second].push_back({centers[centers.size()-1].second, L});
    	g[centers[centers.size()-1].second].push_back({centers[i].second, L});
    }

	fill(dist.begin(), dist.end(), INF);
   	bfs(1, true);
   	int node = max_element(dist.begin(), dist.end()) - dist.begin();
	fill(dist.begin(), dist.end(), INF);
   	return bfs(node, false);
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:85:28: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     for(int i=0; i<N; i++) if(dist[i] == INF)
                            ^~
dreaming.cpp:88:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  fill(dist.begin(), dist.end(), INF);
  ^~~~
dreaming.cpp:94:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<centers.size()-1; i++){
                  ~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 69 ms 7160 KB Output is correct
2 Correct 77 ms 7092 KB Output is correct
3 Correct 44 ms 4728 KB Output is correct
4 Correct 9 ms 1280 KB Output is correct
5 Correct 8 ms 1024 KB Output is correct
6 Correct 15 ms 1792 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 28 ms 3328 KB Output is correct
9 Correct 36 ms 4096 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 51 ms 5496 KB Output is correct
12 Correct 63 ms 6264 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 7160 KB Output is correct
2 Correct 77 ms 7092 KB Output is correct
3 Correct 44 ms 4728 KB Output is correct
4 Correct 9 ms 1280 KB Output is correct
5 Correct 8 ms 1024 KB Output is correct
6 Correct 15 ms 1792 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 28 ms 3328 KB Output is correct
9 Correct 36 ms 4096 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 51 ms 5496 KB Output is correct
12 Correct 63 ms 6264 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 7160 KB Output is correct
2 Correct 77 ms 7092 KB Output is correct
3 Correct 44 ms 4728 KB Output is correct
4 Correct 9 ms 1280 KB Output is correct
5 Correct 8 ms 1024 KB Output is correct
6 Correct 15 ms 1792 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 28 ms 3328 KB Output is correct
9 Correct 36 ms 4096 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 51 ms 5496 KB Output is correct
12 Correct 63 ms 6264 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 80 ms 7160 KB Output is correct
40 Correct 97 ms 7164 KB Output is correct
41 Correct 48 ms 4864 KB Output is correct
42 Correct 9 ms 1408 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 2 ms 384 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 2 ms 384 KB Output is correct
55 Correct 2 ms 384 KB Output is correct
56 Correct 2 ms 384 KB Output is correct
57 Correct 73 ms 8696 KB Output is correct
58 Correct 86 ms 8796 KB Output is correct
59 Correct 71 ms 8568 KB Output is correct
60 Correct 73 ms 8448 KB Output is correct
61 Correct 84 ms 8440 KB Output is correct
62 Correct 73 ms 8440 KB Output is correct
63 Correct 66 ms 8312 KB Output is correct
64 Correct 70 ms 8312 KB Output is correct
65 Correct 83 ms 8312 KB Output is correct
66 Correct 88 ms 8312 KB Output is correct
67 Correct 81 ms 8440 KB Output is correct
68 Correct 91 ms 8440 KB Output is correct
69 Correct 83 ms 8440 KB Output is correct
70 Correct 81 ms 8568 KB Output is correct
71 Correct 2 ms 384 KB Output is correct
72 Correct 4 ms 640 KB Output is correct
73 Correct 4 ms 640 KB Output is correct
74 Correct 3 ms 512 KB Output is correct
75 Correct 4 ms 512 KB Output is correct
76 Correct 4 ms 512 KB Output is correct
77 Correct 3 ms 512 KB Output is correct
78 Correct 7 ms 640 KB Output is correct
79 Correct 6 ms 512 KB Output is correct
80 Correct 97 ms 8440 KB Output is correct
81 Correct 86 ms 8444 KB Output is correct
82 Correct 90 ms 8452 KB Output is correct
83 Correct 82 ms 8572 KB Output is correct
84 Correct 3 ms 512 KB Output is correct
85 Correct 3 ms 512 KB Output is correct
86 Correct 3 ms 512 KB Output is correct
87 Correct 3 ms 512 KB Output is correct
88 Correct 4 ms 512 KB Output is correct
89 Correct 3 ms 512 KB Output is correct
90 Correct 3 ms 512 KB Output is correct
91 Correct 4 ms 512 KB Output is correct
92 Correct 3 ms 512 KB Output is correct
93 Correct 3 ms 512 KB Output is correct
94 Correct 2 ms 384 KB Output is correct
95 Correct 2 ms 384 KB Output is correct
96 Correct 2 ms 384 KB Output is correct
97 Correct 2 ms 384 KB Output is correct
98 Correct 2 ms 384 KB Output is correct
99 Correct 2 ms 384 KB Output is correct
100 Correct 2 ms 384 KB Output is correct
101 Correct 2 ms 384 KB Output is correct
102 Correct 2 ms 384 KB Output is correct
103 Correct 2 ms 384 KB Output is correct
104 Correct 8 ms 1152 KB Output is correct
105 Correct 15 ms 1792 KB Output is correct
106 Correct 2 ms 384 KB Output is correct
107 Correct 29 ms 3328 KB Output is correct
108 Correct 34 ms 4088 KB Output is correct
109 Correct 2 ms 384 KB Output is correct
110 Correct 53 ms 5504 KB Output is correct
111 Correct 74 ms 6264 KB Output is correct
112 Correct 2 ms 384 KB Output is correct
113 Correct 131 ms 7928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 5916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 7160 KB Output is correct
2 Correct 77 ms 7092 KB Output is correct
3 Correct 44 ms 4728 KB Output is correct
4 Correct 9 ms 1280 KB Output is correct
5 Correct 8 ms 1024 KB Output is correct
6 Correct 15 ms 1792 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 28 ms 3328 KB Output is correct
9 Correct 36 ms 4096 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 51 ms 5496 KB Output is correct
12 Correct 63 ms 6264 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 7 ms 640 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 356 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 7160 KB Output is correct
2 Correct 77 ms 7092 KB Output is correct
3 Correct 44 ms 4728 KB Output is correct
4 Correct 9 ms 1280 KB Output is correct
5 Correct 8 ms 1024 KB Output is correct
6 Correct 15 ms 1792 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 28 ms 3328 KB Output is correct
9 Correct 36 ms 4096 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 51 ms 5496 KB Output is correct
12 Correct 63 ms 6264 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 80 ms 7160 KB Output is correct
40 Correct 97 ms 7164 KB Output is correct
41 Correct 48 ms 4864 KB Output is correct
42 Correct 9 ms 1408 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 2 ms 384 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 2 ms 384 KB Output is correct
55 Correct 2 ms 384 KB Output is correct
56 Correct 2 ms 384 KB Output is correct
57 Correct 73 ms 8696 KB Output is correct
58 Correct 86 ms 8796 KB Output is correct
59 Correct 71 ms 8568 KB Output is correct
60 Correct 73 ms 8448 KB Output is correct
61 Correct 84 ms 8440 KB Output is correct
62 Correct 73 ms 8440 KB Output is correct
63 Correct 66 ms 8312 KB Output is correct
64 Correct 70 ms 8312 KB Output is correct
65 Correct 83 ms 8312 KB Output is correct
66 Correct 88 ms 8312 KB Output is correct
67 Correct 81 ms 8440 KB Output is correct
68 Correct 91 ms 8440 KB Output is correct
69 Correct 83 ms 8440 KB Output is correct
70 Correct 81 ms 8568 KB Output is correct
71 Correct 2 ms 384 KB Output is correct
72 Correct 4 ms 640 KB Output is correct
73 Correct 4 ms 640 KB Output is correct
74 Correct 3 ms 512 KB Output is correct
75 Correct 4 ms 512 KB Output is correct
76 Correct 4 ms 512 KB Output is correct
77 Correct 3 ms 512 KB Output is correct
78 Correct 7 ms 640 KB Output is correct
79 Correct 6 ms 512 KB Output is correct
80 Correct 97 ms 8440 KB Output is correct
81 Correct 86 ms 8444 KB Output is correct
82 Correct 90 ms 8452 KB Output is correct
83 Correct 82 ms 8572 KB Output is correct
84 Correct 3 ms 512 KB Output is correct
85 Correct 3 ms 512 KB Output is correct
86 Correct 3 ms 512 KB Output is correct
87 Correct 3 ms 512 KB Output is correct
88 Correct 4 ms 512 KB Output is correct
89 Correct 3 ms 512 KB Output is correct
90 Correct 3 ms 512 KB Output is correct
91 Correct 4 ms 512 KB Output is correct
92 Correct 3 ms 512 KB Output is correct
93 Correct 3 ms 512 KB Output is correct
94 Correct 2 ms 384 KB Output is correct
95 Correct 2 ms 384 KB Output is correct
96 Correct 2 ms 384 KB Output is correct
97 Correct 2 ms 384 KB Output is correct
98 Correct 2 ms 384 KB Output is correct
99 Correct 2 ms 384 KB Output is correct
100 Correct 2 ms 384 KB Output is correct
101 Correct 2 ms 384 KB Output is correct
102 Correct 2 ms 384 KB Output is correct
103 Correct 2 ms 384 KB Output is correct
104 Correct 8 ms 1152 KB Output is correct
105 Correct 15 ms 1792 KB Output is correct
106 Correct 2 ms 384 KB Output is correct
107 Correct 29 ms 3328 KB Output is correct
108 Correct 34 ms 4088 KB Output is correct
109 Correct 2 ms 384 KB Output is correct
110 Correct 53 ms 5504 KB Output is correct
111 Correct 74 ms 6264 KB Output is correct
112 Correct 2 ms 384 KB Output is correct
113 Correct 131 ms 7928 KB Output is correct
114 Execution timed out 1071 ms 5916 KB Time limit exceeded
115 Halted 0 ms 0 KB -