제출 #519020

#제출 시각아이디문제언어결과실행 시간메모리
519020fabijan_cikac경주 (Race) (IOI11_race)C++17
0 / 100
3 ms4940 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, ll> pp; const int MAXN = 2 * 1e5 + 100; const int INF = 2 * 1e9; struct mapa{ int val = INF; }; int n; int k; vector<pp> v[MAXN]; int p[MAXN] = { 0 }; int vel[MAXN] = { 0 }; map<ll, mapa> m; vector<int> s; int sol = INF; int cnt = 0; int dfs(int x, int depth, ll sum, int val, int k){ p[x] = 1; vel[x] = 0; if (val == 1 && sum <= k){ int zb = depth + m[k - sum].val - 1; sol = min(sol, zb); } else if (val == 2 && sum <= k){ s.push_back(sum); m[sum].val = min(m[sum].val, depth); } for (int i = 0; i < v[x].size(); ++i){ int y = v[x][i].first; if (!p[y]){ int rt = dfs(y, depth + 1, sum + v[x][i].second, val, k); if (val == 0) vel[x] += rt; } } p[x] = 0; if (val == 0) return vel[x]; return 0; } int centr(int x){ p[x] = 1; pp maks = {-1, -1}; for (int i = 0; i < v[x].size(); ++i){ int y = v[x][i].first; if (!p[y] && vel[y] > maks.second) maks = {y, vel[y]}; } if (maks.second <= cnt / 2){ p[x] = 0; return x; } else{ int rjes = centr(maks.first); p[x] = 0; return rjes; } } void solve(int x, int K){ s.clear(); for (int i = 0; i < v[x].size(); ++i){ int y = v[x][i].first; if (!p[y]){ dfs(y, 2, v[x][i].second, 1, K); dfs(y, 2, v[x][i].second, 2, K); } } while (!s.empty()){ m[s.back()].val = INF; s.pop_back(); } return; } void decompose(int x, int K){ cnt = 0; dfs(x, 1, 0, 0, K); cnt = vel[x]; int root = centr(x); p[root] = 1; solve(root, K); for (int i = 0; i < v[root].size(); ++i){ int y = v[root][i].first; if (!p[y]) decompose(y, K); } } int best_path(int N, int K, int H[MAXN][2], int L[MAXN]){ ios_base::sync_with_stdio(false); cin.tie(NULL); for (int i = 0; i < N - 1; ++i){ v[H[i][0]].push_back({H[i][1], L[i]}); v[H[i][1]].push_back({H[i][0], L[i]}); } decompose(0, K); if (sol == INF) return -1; else return (sol - 1); return 0; }

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

race.cpp: In function 'int dfs(int, int, ll, int, int)':
race.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int i = 0; i < v[x].size(); ++i){
      |                     ~~^~~~~~~~~~~~~
race.cpp: In function 'int centr(int)':
race.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int i = 0; i < v[x].size(); ++i){
      |                     ~~^~~~~~~~~~~~~
race.cpp: In function 'void solve(int, int)':
race.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for (int i = 0; i < v[x].size(); ++i){
      |                     ~~^~~~~~~~~~~~~
race.cpp: In function 'void decompose(int, int)':
race.cpp:82:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for (int i = 0; i < v[root].size(); ++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...