Submission #1074016

#TimeUsernameProblemLanguageResultExecution timeMemory
1074016IgnutDreaming (IOI13_dreaming)C++17
100 / 100
125 ms18900 KiB
// Ignut #include <bits/stdc++.h> #include "dreaming.h" using namespace std; using ll = long long; const int INF = 1e9 + 123; const int MAXN = 1e5 + 123; vector<pair<int, int>> tree[MAXN]; int dist[MAXN]; void dfs(int v, int par, int d) { dist[v] = d; for (auto [to, w] : tree[v]) if (to != par) dfs(to, v, d + w); } void FindDist(int source) { dfs(source, -1, 0); } bool used[MAXN]; vector<int> comp; void dfs0(int v, int par = -1) { used[v] = true; comp.push_back(v); for (auto [to, w] : tree[v]) if (to != par) dfs0(to, v); } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { for (int i = 0; i < N; i ++) { tree[i].clear(); used[i] = false; } for (int i = 0; i < M; i ++) { tree[A[i]].push_back({B[i], T[i]}); tree[B[i]].push_back({A[i], T[i]}); } vector<pair<int, int>> c; for (int i = 0; i < N; i ++) { if (used[i]) continue; comp.clear(); dfs0(i); FindDist(i); int j = i; for (int v : comp) if (dist[v] > dist[j]) j = v; FindDist(j); map<int, int> d1; for (int v : comp) d1[v] = dist[v]; j = i; for (int v : comp) if (dist[v] > dist[j]) j = v; FindDist(j); int ctr = i, maxDist = INF; for (int v : comp) { int d = max(d1[v], dist[v]); if (d < maxDist) { ctr = v; maxDist = d; } } c.push_back({maxDist, ctr}); } sort(c.begin(), c.end()); reverse(c.begin(), c.end()); for (int i = 1; i < c.size(); i ++) { tree[c[i].second].push_back({c[0].second, L}); tree[c[0].second].push_back({c[i].second, L}); } int res = 0; FindDist(0); int j = 0; for (int i = 0; i < N; i ++) if (dist[i] > dist[j]) j = i; FindDist(j); for (int i = 0; i < N; i ++) res = max(res, dist[i]); return res; }

Compilation message (stderr)

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:77:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for (int i = 1; i < c.size(); i ++) {
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...