제출 #1002153

#제출 시각아이디문제언어결과실행 시간메모리
1002153Tsog경주 (Race) (IOI11_race)C++14
9 / 100
220 ms184824 KiB
#include <bits/stdc++.h> using namespace std; int k, mn = INT_MAX; vector<vector<int>> dp(200001,vector<int>(101,INT_MAX)); vector<pair<int, int>> adj[200001]; vector<vector<pair<int, int>>> path; void dfs(int v, int p) { dp[v][0] = 0; for (auto [i, w] : adj[v]) if (i != p) dfs(i, v); path.assign(k + 1, {}); for (auto [i, w] : adj[v]) { if (i == p) continue; for (int j = w; j <= k; j++) { if (dp[i][j - w] == INT_MAX) continue; if (path[j].size() < 2) path[j].push_back({dp[i][j - w] + 1, i}); else if (dp[i][j - w] + 1 < path[j][0].first) path[j][0] = {dp[i][j - w] + 1, i}; //if (path[j].size() == 2 && path[j][0].first > path[j][1].first) // swap(path[j][0], path[j][1]); dp[v][j] = min(dp[v][j], dp[i][j - w] + 1); } } if (!path[k].empty()) mn = min(mn, path[k][0].first); for (int i = 1; i < k; i++) { if (path[i].empty() || path[k - i].empty()) continue; if (path[i][0].second != path[k - i][0].second) mn = min(mn, path[i][0].first + path[k - i][0].first); // else if (1 < path[k - i].size()) //mn = min(mn, path[i][0].first + path[k - i][1].first); } } int best_path(int N, int K, int H[][2], int L[]) { k = K; for (int i = 0; i < N - 1; i++) { adj[H[i][0]].push_back({H[i][1], L[i]}); adj[H[i][1]].push_back({H[i][0], L[i]}); } dfs(0, -1); if (mn == INT_MAX) return -1; else return mn; }

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

race.cpp: In function 'void dfs(int, int)':
race.cpp:10:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   10 |   for (auto [i, w] : adj[v])
      |             ^
race.cpp:14:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   14 |   for (auto [i, w] : adj[v])
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...