# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1014076 |
2024-07-04T10:28:21 Z |
ZanP |
Dreaming (IOI13_dreaming) |
C++17 |
|
0 ms |
0 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int mxN = 1e6;
const int INF = 1e9;
int n, m, l;
vector<pair<int, int>> pov[mxN];
int td[mxN];
bool vis[mxN];
int maxd = 0, cnt = 0;
pair<int, int> dfs(int u, int par) {
pair<int, int> ans = { 0,u };
vis[u] = true;
for (auto p : pov[u]) {
int v = p.first;
int c = p.second;
if (v != par) {
pair<int, int> q = dfs(v, u);
q.first += c;
ans = max(ans, q);
}
}
return ans;
}
int opt = INF;
int opt_dfs(int u, int tar, int d, int par)
{
if (u == tar) {
opt = d;
return d;
}
int ans = INF;
for (auto p : pov[u]) {
int v = p.first;
int c = p.second;
if (v != par) {
int dis = opt_dfs(v, tar, d, u) - c;
ans = min(ans, dis);
}
}
opt = min(max(ans,d-ans), opt);
return ans;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
int n = N; int m = M; int l = L;
for (int i = 0; i < m; i++) {
int a = A[i], b = B[i], c = T[i];
pov[a].push_back({ b,c });
pov[b].push_back({ a,c });
}
memset(vis, 0, n);
for (int i = 0; i < n; i++) {
if (!vis[i] && pov[i].size() <= 1) {
pair<int, int> p = dfs(i, -1);
pair<int, int> q = dfs(p.second, -1);
maxd = q.first;
opt = INF;
opt_dfs(p.second, q.second, q.first, -1);
td[cnt] = opt;
cnt++;
}
}
if (cnt == 1) {
return maxd;
}
sort(td, td + cnt, isgreater<int,int>);
int ans = l + td[0] + td[1];
if (cnt > 2) { ans = max(ans, 2 * l + td[1] + td[2]); }
return ans;
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:70:24: error: 'isgreater' was not declared in this scope
70 | sort(td, td + cnt, isgreater<int,int>);
| ^~~~~~~~~
dreaming.cpp:70:34: error: expected primary-expression before 'int'
70 | sort(td, td + cnt, isgreater<int,int>);
| ^~~
dreaming.cpp:70:38: error: expected primary-expression before 'int'
70 | sort(td, td + cnt, isgreater<int,int>);
| ^~~