# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
744310 |
2023-05-18T11:52:10 Z |
bane |
Dreaming (IOI13_dreaming) |
C++17 |
|
58 ms |
17896 KB |
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
const int maxN = (int)1e5 + 5;
#define ll long long
vector<vector<pair<ll,ll>>>adj(maxN);
ll vis[maxN], dist[maxN], parent[maxN];
ll mx = 0, source = -1;
ll ans = 0;
void dfs(int u, int p = -1, ll d = 0){
vis[u] = 1;
parent[u] = p;
dist[u] = d;
ans = max(ans, d);
if (mx < d){
mx = d;
source = u;
}
for (auto x : adj[u]){
if (x.first == p){
continue;
}
dfs(x.first, u, x.second + d);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
for (int i = 0; i < M; i++){
//cout<<A[i]<<" "<<B[i]<<endl;
adj[A[i]].push_back({B[i], T[i]});
adj[B[i]].push_back({A[i], T[i]});
}
vector<pair<ll,ll>>centroids;
for (int i = 0; i < N; i++){
if (vis[i])continue;
mx = -1, source = -1;
dfs(i);
int S = source;
mx = -1;
dfs(S);
int E = source;
vector<pair<ll,ll>>path;
// cout<<S<<" "<<E<<endl;
while(E != S){
path.push_back({E, dist[E]});
E = parent[E];
}
path.push_back({E, dist[E]});
reverse(path.begin(), path.end());
ll diameter = path.back().second;
ll best_node = path[0].first, best_dist = 1e18;
for(int j = 0; j < path.size(); j++){
if(max(path[j].second, diameter - path[j].second) < best_dist){
best_node = path[j].first;
best_dist = max(path[j].second, diameter - path[j].second);
}
}
centroids.push_back({best_dist, best_node});
}
// for (auto j : centroids)cout<<j.first<<" "<<j.second<<endl;
sort(centroids.rbegin(), centroids.rend());
if (centroids.size() > 2)ans = max(ans, L + centroids[0].first + centroids[1].first);
if (centroids.size() > 3)ans = max(ans, L * 2 + centroids[1].first + centroids[2].first);
return ans;
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:52:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int j = 0; j < path.size(); j++){
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
17896 KB |
Output is correct |
2 |
Correct |
58 ms |
17780 KB |
Output is correct |
3 |
Correct |
32 ms |
12496 KB |
Output is correct |
4 |
Correct |
8 ms |
4948 KB |
Output is correct |
5 |
Correct |
6 ms |
4180 KB |
Output is correct |
6 |
Correct |
14 ms |
6284 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Incorrect |
2 ms |
2664 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
17896 KB |
Output is correct |
2 |
Correct |
58 ms |
17780 KB |
Output is correct |
3 |
Correct |
32 ms |
12496 KB |
Output is correct |
4 |
Correct |
8 ms |
4948 KB |
Output is correct |
5 |
Correct |
6 ms |
4180 KB |
Output is correct |
6 |
Correct |
14 ms |
6284 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
8688 KB |
Output is correct |
2 |
Correct |
29 ms |
8776 KB |
Output is correct |
3 |
Correct |
30 ms |
8696 KB |
Output is correct |
4 |
Correct |
35 ms |
8768 KB |
Output is correct |
5 |
Correct |
26 ms |
8744 KB |
Output is correct |
6 |
Correct |
34 ms |
10056 KB |
Output is correct |
7 |
Correct |
33 ms |
8992 KB |
Output is correct |
8 |
Correct |
32 ms |
8700 KB |
Output is correct |
9 |
Correct |
27 ms |
8552 KB |
Output is correct |
10 |
Correct |
36 ms |
8932 KB |
Output is correct |
11 |
Correct |
3 ms |
2672 KB |
Output is correct |
12 |
Correct |
13 ms |
7112 KB |
Output is correct |
13 |
Correct |
13 ms |
7152 KB |
Output is correct |
14 |
Correct |
13 ms |
6984 KB |
Output is correct |
15 |
Correct |
13 ms |
6992 KB |
Output is correct |
16 |
Correct |
13 ms |
7008 KB |
Output is correct |
17 |
Correct |
13 ms |
6616 KB |
Output is correct |
18 |
Correct |
12 ms |
7240 KB |
Output is correct |
19 |
Correct |
13 ms |
6984 KB |
Output is correct |
20 |
Correct |
2 ms |
2672 KB |
Output is correct |
21 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Incorrect |
2 ms |
2664 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
17896 KB |
Output is correct |
2 |
Correct |
58 ms |
17780 KB |
Output is correct |
3 |
Correct |
32 ms |
12496 KB |
Output is correct |
4 |
Correct |
8 ms |
4948 KB |
Output is correct |
5 |
Correct |
6 ms |
4180 KB |
Output is correct |
6 |
Correct |
14 ms |
6284 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |