Submission #551369

#TimeUsernameProblemLanguageResultExecution timeMemory
551369razvanDreaming (IOI13_dreaming)C++14
32 / 100
50 ms12364 KiB
#include "dreaming.h" #include <iostream> #include <cstdio> #include <fstream> #include <vector> #include <algorithm> #define pb push_back using namespace std; const int maxn = 100005; struct xy { int x, y; }; vector<xy> v[maxn]; int done[maxn]; int bgst[maxn], ibgst[maxn]; //int ibgst2[maxn]; int now = -1, inow; //int lft, rgh; int ansnow, iansnow; void dfs(int x, int p) { done[x] = true; int big1 = 0, big2 = 0, ibig1 = -1, ibig2 = -1; for(auto u : v[x]) { if(u.x != p) { dfs(u.x, x); if(bgst[u.x] + u.y > big1) { big2 = big1; ibig2 = ibig1; big1 = bgst[u.x] + u.y; ibig1 = u.x; } else if(bgst[u.x] + u.y > big2) { big2 = bgst[u.x] + u.y; ibig2 = u.x; } } } bgst[x] = big1; ibgst[x] = ibig1; //ibgst2[x] = ibig2; if(big1 + big2 > now) { now = big1 + big2; inow = x; } } void dfs2(int x) { if(max(bgst[x], now - bgst[x]) < ansnow) { ansnow = max(bgst[x], now - bgst[x]); iansnow = x; } if(ibgst[x] != -1) dfs2(ibgst[x]); } vector<int> points; int best = -1, ibest; int travelTime(int n, int m, int l, int a[], int b[], int t[]) { int i, j; for(i = 0; i < m; i ++) { v[a[i]].pb({b[i], t[i]}); v[b[i]].pb({a[i], t[i]}); } for(i = 0; i < n; i ++) { if(done[i] == false) { done[i] = true; now = -1; dfs(i, -1); //lft = bgst[inow]; //rgh = now - lft; ansnow = bgst[inow]; iansnow = i; //cout << "now: " << now << ' ' << inow << " " << ansnow << ' ' << iansnow << '\n'; dfs2(ibgst[inow]); //cout << "ansnow: " << ansnow << ' ' << iansnow << '\n'; points.pb(iansnow); if(ansnow > best) { best = ansnow; ibest = iansnow; } } } //cout << "best, ibest: " << best << ' ' << ibest << '\n'; for(auto w : points) { //cout << "point " << w << '\n'; if(w != ibest) { v[ibest].pb({w, l}); v[w].pb({ibest, l}); } } for(i = 0; i < n; i ++) { bgst[i] = ibgst[i] = 0; //ibgst2[i] = 0; } now = -1; dfs(0, -1); return now; }

Compilation message (stderr)

dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:25:41: warning: variable 'ibig2' set but not used [-Wunused-but-set-variable]
   25 |     int big1 = 0, big2 = 0, ibig1 = -1, ibig2 = -1;
      |                                         ^~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:61:12: warning: unused variable 'j' [-Wunused-variable]
   61 |     int i, j;
      |            ^
#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...