Submission #90178

# Submission time Handle Problem Language Result Execution time Memory
90178 2018-12-20T17:51:03 Z FiloSanza Dreaming (IOI13_dreaming) C++14
47 / 100
1000 ms 9080 KB
#pragma GCC optimize("O3")
#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<pair<int, int>> centers;
vector<int> temp;
vector<int> padre;
queue<int> changed;
queue<int> q;
 
int bfs(int node, bool precalcolo){
	dist[node] = 0;
	q.push(node);
 
	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;
				changed.push(i.to);
				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;
		while(padre[curr] != -1){
			curr = padre[curr];
			if(max(diameter-dist[curr], dist[curr]) < maxi){
				maxi = max(diameter-dist[curr], dist[curr]);
				center = curr;
			}
		}
 
		centers.push_back({maxi, center});
	}
 
	while(!changed.empty()){
		padre[changed.front()] = -1;
		changed.pop();
	}

	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);
	centers.reserve(N);
	temp.reserve(N);
	padre.resize(N, -1);
 
    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:87:28: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     for(int i=0; i<N; i++) if(dist[i] == INF)
                            ^~
dreaming.cpp:90: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:96: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 70 ms 7544 KB Output is correct
2 Correct 106 ms 7544 KB Output is correct
3 Correct 45 ms 5212 KB Output is correct
4 Correct 9 ms 1408 KB Output is correct
5 Correct 8 ms 1152 KB Output is correct
6 Correct 17 ms 1920 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 30 ms 3456 KB Output is correct
9 Correct 47 ms 4292 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 59 ms 5880 KB Output is correct
12 Correct 64 ms 6648 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 7544 KB Output is correct
2 Correct 106 ms 7544 KB Output is correct
3 Correct 45 ms 5212 KB Output is correct
4 Correct 9 ms 1408 KB Output is correct
5 Correct 8 ms 1152 KB Output is correct
6 Correct 17 ms 1920 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 30 ms 3456 KB Output is correct
9 Correct 47 ms 4292 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 59 ms 5880 KB Output is correct
12 Correct 64 ms 6648 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 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 256 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 1 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 7544 KB Output is correct
2 Correct 106 ms 7544 KB Output is correct
3 Correct 45 ms 5212 KB Output is correct
4 Correct 9 ms 1408 KB Output is correct
5 Correct 8 ms 1152 KB Output is correct
6 Correct 17 ms 1920 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 30 ms 3456 KB Output is correct
9 Correct 47 ms 4292 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 59 ms 5880 KB Output is correct
12 Correct 64 ms 6648 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 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 256 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 1 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 82 ms 7544 KB Output is correct
40 Correct 74 ms 7672 KB Output is correct
41 Correct 49 ms 5112 KB Output is correct
42 Correct 10 ms 1408 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 2 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 3 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 86 ms 9068 KB Output is correct
58 Correct 106 ms 9080 KB Output is correct
59 Correct 92 ms 9000 KB Output is correct
60 Correct 89 ms 8952 KB Output is correct
61 Correct 87 ms 8824 KB Output is correct
62 Correct 99 ms 8952 KB Output is correct
63 Correct 96 ms 8852 KB Output is correct
64 Correct 93 ms 8948 KB Output is correct
65 Correct 80 ms 8824 KB Output is correct
66 Correct 79 ms 8696 KB Output is correct
67 Correct 103 ms 9080 KB Output is correct
68 Correct 86 ms 8900 KB Output is correct
69 Correct 95 ms 8844 KB Output is correct
70 Correct 101 ms 8956 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 4 ms 640 KB Output is correct
75 Correct 4 ms 640 KB Output is correct
76 Correct 4 ms 640 KB Output is correct
77 Correct 4 ms 640 KB Output is correct
78 Correct 4 ms 640 KB Output is correct
79 Correct 4 ms 640 KB Output is correct
80 Correct 88 ms 8824 KB Output is correct
81 Correct 84 ms 8952 KB Output is correct
82 Correct 94 ms 8952 KB Output is correct
83 Correct 97 ms 9048 KB Output is correct
84 Correct 4 ms 640 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 3 ms 512 KB Output is correct
89 Correct 3 ms 640 KB Output is correct
90 Correct 3 ms 512 KB Output is correct
91 Correct 4 ms 640 KB Output is correct
92 Correct 3 ms 512 KB Output is correct
93 Correct 4 ms 640 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 1148 KB Output is correct
105 Correct 15 ms 1920 KB Output is correct
106 Correct 2 ms 384 KB Output is correct
107 Correct 32 ms 3576 KB Output is correct
108 Correct 40 ms 4344 KB Output is correct
109 Correct 2 ms 384 KB Output is correct
110 Correct 63 ms 5816 KB Output is correct
111 Correct 63 ms 6648 KB Output is correct
112 Correct 2 ms 384 KB Output is correct
113 Correct 134 ms 8248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 5896 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 70 ms 7544 KB Output is correct
2 Correct 106 ms 7544 KB Output is correct
3 Correct 45 ms 5212 KB Output is correct
4 Correct 9 ms 1408 KB Output is correct
5 Correct 8 ms 1152 KB Output is correct
6 Correct 17 ms 1920 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 30 ms 3456 KB Output is correct
9 Correct 47 ms 4292 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 59 ms 5880 KB Output is correct
12 Correct 64 ms 6648 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 4 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 5 ms 640 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 5 ms 640 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 3 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 2 ms 384 KB Output is correct
40 Runtime error 2 ms 384 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 70 ms 7544 KB Output is correct
2 Correct 106 ms 7544 KB Output is correct
3 Correct 45 ms 5212 KB Output is correct
4 Correct 9 ms 1408 KB Output is correct
5 Correct 8 ms 1152 KB Output is correct
6 Correct 17 ms 1920 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 30 ms 3456 KB Output is correct
9 Correct 47 ms 4292 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 59 ms 5880 KB Output is correct
12 Correct 64 ms 6648 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 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 256 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 1 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 82 ms 7544 KB Output is correct
40 Correct 74 ms 7672 KB Output is correct
41 Correct 49 ms 5112 KB Output is correct
42 Correct 10 ms 1408 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 2 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 3 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 86 ms 9068 KB Output is correct
58 Correct 106 ms 9080 KB Output is correct
59 Correct 92 ms 9000 KB Output is correct
60 Correct 89 ms 8952 KB Output is correct
61 Correct 87 ms 8824 KB Output is correct
62 Correct 99 ms 8952 KB Output is correct
63 Correct 96 ms 8852 KB Output is correct
64 Correct 93 ms 8948 KB Output is correct
65 Correct 80 ms 8824 KB Output is correct
66 Correct 79 ms 8696 KB Output is correct
67 Correct 103 ms 9080 KB Output is correct
68 Correct 86 ms 8900 KB Output is correct
69 Correct 95 ms 8844 KB Output is correct
70 Correct 101 ms 8956 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 4 ms 640 KB Output is correct
75 Correct 4 ms 640 KB Output is correct
76 Correct 4 ms 640 KB Output is correct
77 Correct 4 ms 640 KB Output is correct
78 Correct 4 ms 640 KB Output is correct
79 Correct 4 ms 640 KB Output is correct
80 Correct 88 ms 8824 KB Output is correct
81 Correct 84 ms 8952 KB Output is correct
82 Correct 94 ms 8952 KB Output is correct
83 Correct 97 ms 9048 KB Output is correct
84 Correct 4 ms 640 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 3 ms 512 KB Output is correct
89 Correct 3 ms 640 KB Output is correct
90 Correct 3 ms 512 KB Output is correct
91 Correct 4 ms 640 KB Output is correct
92 Correct 3 ms 512 KB Output is correct
93 Correct 4 ms 640 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 1148 KB Output is correct
105 Correct 15 ms 1920 KB Output is correct
106 Correct 2 ms 384 KB Output is correct
107 Correct 32 ms 3576 KB Output is correct
108 Correct 40 ms 4344 KB Output is correct
109 Correct 2 ms 384 KB Output is correct
110 Correct 63 ms 5816 KB Output is correct
111 Correct 63 ms 6648 KB Output is correct
112 Correct 2 ms 384 KB Output is correct
113 Correct 134 ms 8248 KB Output is correct
114 Execution timed out 1088 ms 5896 KB Time limit exceeded
115 Halted 0 ms 0 KB -