Submission #744398

#TimeUsernameProblemLanguageResultExecution timeMemory
744398MODDIDreaming (IOI13_dreaming)C++14
100 / 100
191 ms28932 KiB
#include "dreaming.h" #include <bits/stdc++.h> #define ll long long #define mp make_pair #define pb push_back using namespace std; vector<vector<pair<int, int> > > G; vector<bool> vis; ll ans, help = 0; void dfs(int at, int parent, long long dist, vector<pair<int, long long> >& paths){ vis[at] = true; paths.push_back(make_pair(at, dist)); for(auto next : G[at]){ if(next.first != parent){ dfs(next.first, at, dist + next.second, paths); } } } void solve(int start){ vector<pair<int, ll> > d, d2; dfs(start,start, 0, d); ll len1 = -1; int node1; for(auto t : d){ if(len1 < t.second){ len1 = t.second; node1 = t.first; } } d.clear(); dfs(node1,node1, 0, d); ll len2 = -1; int node2; map<int,ll> store; for(auto t : d){ store[t.first] = t.second; if(len2 < t.second){ len2 = t.second; node2 = t.first; } } help = max(help, len2); dfs(node2,node2, 0, d2); for(auto t : d2){ ans = min(ans, max(t.second, store[t.first])); } } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { vis.resize(N, false); G.resize(N); for(int i = 0; i < M; i++){ G[A[i]].pb(mp(B[i], T[i])); G[B[i]].pb(mp(A[i], T[i])); } vector<ll> arr; for(int i = 0; i < N; i++){ if(!vis[i]){ ans = 2e9; solve(i); arr.pb(ans); } else continue; } sort(arr.rbegin(), arr.rend()); if(arr.size() == 1) return max(arr[0], help); else if(arr.size() == 2) return max(help, arr[0] + arr[1] + L); else return max(max(arr[0] + arr[1] + L, arr[1] + arr[2] + 2 * L), help); }

Compilation message (stderr)

dreaming.cpp: In function 'void solve(int)':
dreaming.cpp:43:5: warning: 'node2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |  dfs(node2,node2, 0, d2);
      |  ~~~^~~~~~~~~~~~~~~~~~~~
dreaming.cpp:31:5: warning: 'node1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |  dfs(node1,node1, 0, d);
      |  ~~~^~~~~~~~~~~~~~~~~~~
#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...