Submission #535423

#TimeUsernameProblemLanguageResultExecution timeMemory
535423AngusWongDreaming (IOI13_dreaming)C++17
18 / 100
43 ms16280 KiB
#include "dreaming.h" #include <bits/stdc++.h> #define pii pair<int, int> #define f first #define s second using namespace std; int n, m, l, dis[100001], leaf[100001], len, stp, edp, ans; vector<pii> v[100001]; vector<int> path, mx; void dfs(int x, int prev=-1){ dis[x]=0; leaf[x]=x; int mx=x, mx2=x; for (pii i: v[x]){ if (i.f==prev) continue; dfs(i.f, x); dis[i.f]+=i.s; if (dis[i.f]>dis[mx]) mx2=mx, mx=i.f; else if (dis[i.f]>dis[mx2]) mx2=i.f; } if (dis[mx]+dis[mx2]>len) len=dis[mx]+dis[mx2], stp=leaf[mx], edp=leaf[mx2]; dis[x]=dis[mx]; leaf[x]=leaf[mx]; } bool get_path(int x, int prev=-1){ if (x==edp) return true; for (pii i: v[x]){ if (i.f==prev) continue; if (get_path(i.f, x)){ path.push_back(i.s); return true; } } return false; } int max_length(int x){ len=stp=edp=-1; dfs(x); path.clear(); get_path(stp); if (path.empty()) return 0; for (int i=1; i<path.size(); i++) path[i]+=path[i-1]; int ans=2e9; for (int i=0; i<path.size(); i++){ int t=path[i]; // 0..i if (i<path.size()) t=max(t, path[path.size()-1]-path[i]); ans=min(ans, t); } return ans; } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { n=N, m=M, l=L; for (int i=0; i<m; i++){ v[A[i]].push_back({B[i], T[i]}); v[B[i]].push_back({A[i], T[i]}); } for (int i=0; i<n; i++) dis[i]=-1; for (int i=0; i<n; i++){ if (dis[i]==-1) mx.push_back(max_length(i)); } sort(mx.begin(), mx.end(), greater<int>()); ans=mx[0]; if (mx.size()>1) ans=max(ans, mx[0]+mx[1]+l); if (mx.size()>2) ans=max(ans, mx[1]+mx[2]+l*2); return ans; }

Compilation message (stderr)

dreaming.cpp: In function 'int max_length(int)':
dreaming.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i=1; i<path.size(); i++) path[i]+=path[i-1];
      |                   ~^~~~~~~~~~~~
dreaming.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i=0; i<path.size(); i++){
      |                   ~^~~~~~~~~~~~
dreaming.cpp:50:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if (i<path.size()) t=max(t, path[path.size()-1]-path[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...