제출 #838867

#제출 시각아이디문제언어결과실행 시간메모리
838867Shreyan_Paliwal경주 (Race) (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
// #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define int long long template<typename T> string tostr(const T& value) { ostringstream oss; oss << value; return oss.str(); } template<typename... Args> string fstr(const string& format, Args... args) { string result = format; size_t pos = 0; size_t argIndex = 0; auto replaceArg = [&](const auto& arg) { pos = result.find("{}", pos); if (pos != string::npos) { result.replace(pos, 2, tostr(arg)); ++argIndex; } }; (replaceArg(args), ...); return result; } template<int SZ> struct Tree { int n; vector<pair<int,int>> adj[SZ]; void init(int N, int H[][2], int L[]) { n = N; for (int i = 0; i < n-1; i++) { int a, b, c; cin >> a >> b >> c; adj[H[i][0]].push_back({H[i][1], L[i]}); adj[H[i][1]].push_back({H[i][0], L[i]}); } } }; const int maxn = 200000; int n, k; int sz[maxn], dpth[maxn], ldpth[maxn]; Tree<maxn> tree; unordered_map<int,int> m[maxn]; int ans = INT_MAX; int dfs(int nd, int par, int l) { sz[nd] = 1, dpth[nd] = dpth[par] + 1; ldpth[nd] = l; for (auto i : tree.adj[nd]) if (i.first != par) sz[nd] += dfs(i.first, nd, l + i.second); return sz[nd]; } inline int mget(int nd, int dist) { // dist to find = ldist[nd] + dist; dist += ldpth[nd]; if (m[nd].find(dist) == m[nd].end()) return INT_MAX; return m[nd][dist]; } inline void upd_min(int nd, int k, int v) { if (m[nd].find(k) == m[nd].end()) {m[nd][k] = v; return; } // cout << "Y " << nd << ' ' << k << ' ' << (m[nd].find(k) == m[nd].end()) << ' ' << m[nd][k] << ' '; m[nd][k] = min(m[nd][k], v); // cout << m[nd][k] << endl; } void msl(int nd, int par) { for (auto i : tree.adj[nd]) if (i.first != par) msl(i.first, nd); int hch = -1, hb = -1; for (auto i : tree.adj[nd]) if (i.first != par) if (hch == -1 || hb < sz[i.first]) hch = i.first, hb = sz[i.first]; // cout << "Z " << nd << ' ' << (hch == -1) << endl; if (hch == -1) {m[nd][ldpth[nd]] = dpth[nd]; // cout << "---------" << endl << nd << endl; // cout << "X "; // for (auto i : m[nd]) cout << i.first << ' ' << i.second << ' '; // cout << endl; return;} // cout << "----" << endl; swap(m[nd], m[hch]); // cout << nd << endl; for (auto i : tree.adj[nd]) if (i.first != par && i.first != hch) for (auto j : m[i.first]) { // cout << j.first << ' ' << j.second << endl; // (dist[i], dpth[i]) --> (dist[i] - dist[nd], dpth[i] - dpth[nd]) int val = mget(nd, k - (j.first - ldpth[nd])); if (val != INT_MAX) ans = min(ans, j.second + mget(nd, k - (j.first - ldpth[nd])) - 2*dpth[nd]); // if (val != INT_MAX) // cout << nd << ' ' << j.first << ' ' << j.second << ' ' << j.second + mget(nd, k - (j.first - ldpth[nd])) - 2*dpth[nd] << endl; upd_min(nd, j.first, j.second); } // cout << nd << ' ' << mget(nd, k) - dpth[nd] << endl; // cout << "X "; // for (auto i : m[nd]) cout << i.first << ' ' << i.second << ' '; // cout << endl; ans = min(ans, mget(nd, k) - dpth[nd]); upd_min(nd, ldpth[nd], dpth[nd]); } int best_path(int N, int K, int H[][2], int L[]) { n = N, k = K; tree.init(n, H, L); dfs(0, 0, 0); msl(0, 0); return ans; } // #define LOCAL // #define CODEFORCES // signed main() { // #ifndef LOCAL // cin.tie(nullptr) -> ios::sync_with_stdio(false); // #endif // #ifdef LOCAL // freopen("main.in", "r", stdin); // #endif // int t; // #ifdef CODEFORCES // cin >> t; // #endif // #ifndef CODEFORCES // t=1; // #endif // while(t--) solve(); // return 0; // }

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

/usr/bin/ld: /tmp/ccwuQHd9.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status