답안 #90171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90171 2018-12-20T17:34:17 Z FiloSanza 꿈 (IOI13_dreaming) C++14
47 / 100
1000 ms 9116 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;
 
int bfs(int node, bool precalcolo){

	queue<int> q;
	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;
		// cout << curr <<"\n";
		// cout << "\t" << max(diameter-dist[curr], dist[curr]) << " " << maxi << "\n";
		while(padre[curr] != -1){
			//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});
	}
 
	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:93:28: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     for(int i=0; i<N; i++) if(dist[i] == INF)
                            ^~
dreaming.cpp:96: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:102:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<centers.size()-1; i++){
                  ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 7544 KB Output is correct
2 Correct 67 ms 7544 KB Output is correct
3 Correct 43 ms 5120 KB Output is correct
4 Correct 10 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 41 ms 4216 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 58 ms 5880 KB Output is correct
12 Correct 77 ms 6648 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 7544 KB Output is correct
2 Correct 67 ms 7544 KB Output is correct
3 Correct 43 ms 5120 KB Output is correct
4 Correct 10 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 41 ms 4216 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 58 ms 5880 KB Output is correct
12 Correct 77 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 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 3 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
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 7544 KB Output is correct
2 Correct 67 ms 7544 KB Output is correct
3 Correct 43 ms 5120 KB Output is correct
4 Correct 10 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 41 ms 4216 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 58 ms 5880 KB Output is correct
12 Correct 77 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 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 3 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 82 ms 7568 KB Output is correct
40 Correct 90 ms 7548 KB Output is correct
41 Correct 45 ms 4984 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 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 95 ms 9116 KB Output is correct
58 Correct 98 ms 9080 KB Output is correct
59 Correct 95 ms 8868 KB Output is correct
60 Correct 82 ms 8968 KB Output is correct
61 Correct 92 ms 8952 KB Output is correct
62 Correct 101 ms 8840 KB Output is correct
63 Correct 86 ms 8824 KB Output is correct
64 Correct 90 ms 8824 KB Output is correct
65 Correct 96 ms 8824 KB Output is correct
66 Correct 90 ms 8768 KB Output is correct
67 Correct 88 ms 8952 KB Output is correct
68 Correct 85 ms 8824 KB Output is correct
69 Correct 88 ms 8824 KB Output is correct
70 Correct 99 ms 8952 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 3 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 3 ms 640 KB Output is correct
80 Correct 83 ms 8824 KB Output is correct
81 Correct 105 ms 8920 KB Output is correct
82 Correct 87 ms 8828 KB Output is correct
83 Correct 102 ms 8872 KB Output is correct
84 Correct 4 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 640 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 640 KB Output is correct
92 Correct 4 ms 640 KB Output is correct
93 Correct 3 ms 512 KB Output is correct
94 Correct 3 ms 356 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 356 KB Output is correct
102 Correct 2 ms 384 KB Output is correct
103 Correct 2 ms 384 KB Output is correct
104 Correct 7 ms 1152 KB Output is correct
105 Correct 16 ms 1920 KB Output is correct
106 Correct 2 ms 384 KB Output is correct
107 Correct 30 ms 3548 KB Output is correct
108 Correct 42 ms 4260 KB Output is correct
109 Correct 2 ms 384 KB Output is correct
110 Correct 76 ms 5804 KB Output is correct
111 Correct 92 ms 6616 KB Output is correct
112 Correct 3 ms 384 KB Output is correct
113 Correct 159 ms 8180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1060 ms 5704 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 7544 KB Output is correct
2 Correct 67 ms 7544 KB Output is correct
3 Correct 43 ms 5120 KB Output is correct
4 Correct 10 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 41 ms 4216 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 58 ms 5880 KB Output is correct
12 Correct 77 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 4 ms 512 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 2 ms 384 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 408 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 3 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 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 7544 KB Output is correct
2 Correct 67 ms 7544 KB Output is correct
3 Correct 43 ms 5120 KB Output is correct
4 Correct 10 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 41 ms 4216 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 58 ms 5880 KB Output is correct
12 Correct 77 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 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 3 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 82 ms 7568 KB Output is correct
40 Correct 90 ms 7548 KB Output is correct
41 Correct 45 ms 4984 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 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 95 ms 9116 KB Output is correct
58 Correct 98 ms 9080 KB Output is correct
59 Correct 95 ms 8868 KB Output is correct
60 Correct 82 ms 8968 KB Output is correct
61 Correct 92 ms 8952 KB Output is correct
62 Correct 101 ms 8840 KB Output is correct
63 Correct 86 ms 8824 KB Output is correct
64 Correct 90 ms 8824 KB Output is correct
65 Correct 96 ms 8824 KB Output is correct
66 Correct 90 ms 8768 KB Output is correct
67 Correct 88 ms 8952 KB Output is correct
68 Correct 85 ms 8824 KB Output is correct
69 Correct 88 ms 8824 KB Output is correct
70 Correct 99 ms 8952 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 3 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 3 ms 640 KB Output is correct
80 Correct 83 ms 8824 KB Output is correct
81 Correct 105 ms 8920 KB Output is correct
82 Correct 87 ms 8828 KB Output is correct
83 Correct 102 ms 8872 KB Output is correct
84 Correct 4 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 640 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 640 KB Output is correct
92 Correct 4 ms 640 KB Output is correct
93 Correct 3 ms 512 KB Output is correct
94 Correct 3 ms 356 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 356 KB Output is correct
102 Correct 2 ms 384 KB Output is correct
103 Correct 2 ms 384 KB Output is correct
104 Correct 7 ms 1152 KB Output is correct
105 Correct 16 ms 1920 KB Output is correct
106 Correct 2 ms 384 KB Output is correct
107 Correct 30 ms 3548 KB Output is correct
108 Correct 42 ms 4260 KB Output is correct
109 Correct 2 ms 384 KB Output is correct
110 Correct 76 ms 5804 KB Output is correct
111 Correct 92 ms 6616 KB Output is correct
112 Correct 3 ms 384 KB Output is correct
113 Correct 159 ms 8180 KB Output is correct
114 Execution timed out 1060 ms 5704 KB Time limit exceeded
115 Halted 0 ms 0 KB -