제출 #638960

#제출 시각아이디문제언어결과실행 시간메모리
638960BackNoob경주 (Race) (IOI11_race)C++14
9 / 100
3055 ms33224 KiB
#include <bits/stdc++.h> #include "race.h" #define ll long long #define fi first #define se second #define endl '\n' #define MASK(i) (1LL << (i)) #define ull unsigned long long #define ld long double #define pb push_back #define all(x) (x).begin() , (x).end() #define BIT(x , i) ((x >> (i)) & 1) #define TASK "task" #define sz(s) (int) (s).size() using namespace std; const int mxN = 2e5 + 227; const int inf = 1e9 + 277; const int mod = 1e9 + 7; const ll infll = 1e18 + 7; const int base = 307; const int LOG = 20; template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } ll n; ll k; int res = inf; int h[mxN][2]; int l[mxN]; int sub[mxN]; int dist[mxN]; int parcen[mxN]; vector<int> node; vector<pair<int, int>> adj[mxN]; ll rdist[mxN]; bool removed[mxN]; int mp[mxN]; vector<int> visit; void dfs(int u, int p) { for(auto it : adj[u]) { int v = it.fi; int c = it.se; if(v == p) continue; rdist[v] = rdist[u] + c; dist[v] = dist[u] + 1; dfs(v, u); } } void dfs_sz(int u, int p) { sub[u] = 1; for(auto it : adj[u]) { int v = it.fi; int c = it.se; if(v == p || removed[v] == true) continue; dfs_sz(v, u); sub[u] += sub[v]; } } int dfs_cen(int u, int p, int n) { for(auto it : adj[u]) { int v = it.fi; int c = it.se; if(v == p || removed[v] == true) continue; if(sub[u] > n / 2) return dfs_cen(v, u, n); } return u; } void find_best(int u, int p, int root) { visit.pb(u); if(u != root) node.pb(u); for(auto it : adj[u]) { int v = it.fi; int c = it.se; if(v == p || removed[v] == true) continue; rdist[v] = rdist[u] + c; dist[v] = dist[u] + 1; if(rdist[v] == k) minimize(res, dist[v]); if(k > rdist[v]) { minimize(res, dist[v] + mp[k - rdist[v]]); } else continue; find_best(v, u, root); if(u == root) { for(auto it : node) { minimize(mp[rdist[it]], dist[it]); } node.clear(); } } } void init_centroid(int u, int p) { parcen[u] = p; dfs_sz(u, -1); int c = dfs_cen(u, -1, sub[u]); node.clear(); visit.clear(); rdist[c] = 0; dist[c] = 0; find_best(c, -1, c); removed[c] = true; for(auto it : visit) mp[rdist[it]] = inf; /* cout << "Cen : " << c << endl; sort(all(visit)); for(auto it : visit) cout << it << ' '; cout << endl; */ for(auto it : adj[c]) { int v = it.fi; if(removed[v] == false) init_centroid(v, u); } } int best_path(int N, int K, int h[][2], int l[]) { n = N; k = K; for(int i = 0; i < n - 1; i++) { int u = h[i][0]; int v = h[i][1]; ++u; ++v; adj[u].pb({v, l[i]}); adj[v].pb({u, l[i]}); } for(int i = 0; i <= k; i++) mp[i] = inf; //par[1][0] = 1; //for(int j = 1; j <= LOG; j++) //for(int i = 1; i <= n; i++) par[i][j] = par[par[i][j - 1]][j - 1]; init_centroid(1, -1); if(res == inf) return -1; return res; }

컴파일 시 표준 에러 (stderr) 메시지

race.cpp: In function 'void dfs_sz(int, int)':
race.cpp:63:13: warning: unused variable 'c' [-Wunused-variable]
   63 |         int c = it.se;
      |             ^
race.cpp: In function 'int dfs_cen(int, int, int)':
race.cpp:74:13: warning: unused variable 'c' [-Wunused-variable]
   74 |         int c = it.se;
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...