Submission #76652

#TimeUsernameProblemLanguageResultExecution timeMemory
76652Shafin666Dreaming (IOI13_dreaming)C++14
0 / 100
71 ms15096 KiB
#include <bits/stdc++.h> #include "dreaming.h" using namespace std; struct edge { int to, cost; /*edge(int _to, int _cost) { to = _to; cost = _cost; }*/ }; const int MAX_N = 123456; vector<edge> adj[MAX_N]; vector<int> R; bool visited[MAX_N]; int maxdist, one, two, point; edge parent[MAX_N]; void dfs1(int u, int par, int val) { visited[u] = 1; int i, mx = 0; if(u == par && !adj[u].size()) {point = u; return;} for(i = 0; i < (int) adj[u].size(); i++) { edge v = adj[u][i]; if(visited[v.to] || v.to == par) continue; if(v.cost + val > mx) point = v.to, mx = v.cost + val; dfs1(v.to, u, v.cost + val); } } void dfs2(int u, int par, int val) { visited[u] = 0; int i, mx = 0; if(u == par && !adj[u].size()) { point = u; maxdist = 0; edge v; v.cost = 0; v.to = u; parent[u] = v; return;} for(i = 0; i < (int) adj[u].size(); i++) { edge v = adj[u][i]; if(!visited[v.to] || v.to == par) continue; if(v.cost + val > mx) point = v.to, mx = v.cost + val, maxdist = mx; dfs2(v.to, u, v.cost + val); parent[v.to] = v; parent[v.to].to = u; } visited[u] = 1; } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { int i, ans = 0; for(i = 0; i < M; i++) { edge v; v.to = B[i]; v.cost = T[i]; adj[A[i]].push_back(v); v.to = A[i]; adj[B[i]].push_back(v); } for(i = 0; i < N; i++) { if(visited[i]) continue; dfs1(i, i, 0); one = point; dfs2(one, one, 0); two = point; ans = max(ans, maxdist); int able = maxdist/2, now = 0, d = 0; for(i = two; i != one; i = parent[i].to) { if(d + parent[i].cost > able) { d = min(d + parent[i].cost, maxdist-d); break; } d += parent[i].cost; } R.push_back(d); } sort(R.begin(), R.end(), greater<int>()); if(!M) return 2*L; if(R.size() > 1) ans = max(ans, R[0]+L+R[1]); if(R.size() > 2) ans = max(ans, R[1]+L+L+R[2]); return ans; }

Compilation message (stderr)

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:71:31: warning: unused variable 'now' [-Wunused-variable]
         int able = maxdist/2, now = 0, d = 0;
                               ^~~
#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...