# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
741668 | 2023-05-14T14:14:48 Z | vjudge1 | Dreaming (IOI13_dreaming) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "dreaming.h" using namespace std; #define endl '\n' #define ll long long #define all(x) x.begin(), x.end() vector<pair<int, int>> g[100005]; ll sz[100005]; vector<int> group; int getSize(int n, int p = -1) { visited[n] = 1; group.push_back(n); sz[n] = 0; for (auto x : g[n]) { if (x.first == p) continue; sz[n] += getSize(x.first, n) + x.second; } return sz[n]; } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { 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]}); } bool visited[N + 2]; vector<int> groups; for (int i = 0; i < N; i++) { if (visited[i]) continue; group.clear(); getSize(i); int diff = INT_MAX; for (auto x : group) { if (abs(sz[i] / 2 - sz[x]) < diff) { diff = abs(sz[i] / 2 - sz[x]); } } group.push_back(diff); } sort(all(group)); reverse(all(group)); int ans = 0; for (int i = 1; i < group.size(); i++) { ans = max(ans, group[i] + group[0] + L); } return ans; }