제출 #1316790

#제출 시각아이디문제언어결과실행 시간메모리
1316790tsetsenbileg꿈 (IOI13_dreaming)C++20
컴파일 에러
0 ms0 KiB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pr = pair<int, int>;
#define pb push_back
const int INF = 1e9+7;
vector<vector<pr>> edge;
vector<int> dp, maxd;
int res = 0, curm;

int dfs1(int node, int par) {
    int ans = 0;
    for (auto [next, val] : edge[node]) {
        if (next == par) continue;
        int t = dfs1(next, node);
        res = max(res, t + ans + val);
        ans = max(ans, t + val);
    }
    return dp[node] = ans;
}

void dfs2(int node, int par, int parv) {
    int sz = edge[node].size();
    int ans = parv;
    vector<int> pref(sz+1, 0), suff(sz+2, 0);
    for (int i = 0; i < sz; i++) {
        if (edge[node][i].first == par) pref[i+1] = pref[i];
        else pref[i+1] = max(pref[i], dp[edge[node][i].first] + edge[node][i].second);
    }
    for (int i = sz-1; i >= 0; i--) {
        if (edge[node][i].first == par) suff[i+1]; = suff[i+2];
        else suff[i+1] = max(suff[i+2], dp[edge[node][i].first] + edge[node][i].second);
    }
    ans = max(ans, pref[sz]);
    for (int i = 0; i < sz; i++) {
        if (edge[node][i].first == par) continue;
        dfs2(edge[node][i].first, node, max({parv, pref[i], suff[i+2]}) + edge[node][i].second);
    }
    curm = min(curm, max(parv, pref[sz]));
    return;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    edge.resize(N);
    dp.assign(N, -1);
    maxd.assign(N, -1);
    for (int i = 0; i < M; i++) {
        edge[A[i]].pb({B[i], T[i]});
        edge[B[i]].pb({A[i], T[i]});
    }
    int mx = 0;
    vector<int> part;
    for (int i = 0; i < N; i++) {
        if (dp[i] == -1) {
            curm = INF;
            dfs1(i, -1);
            int t = curm;
            part.pb(t);
        }
    }
    sort(part.rbegin(), part.rend());
    if (part.size() > 1)
    res = max(res, part[0] + part[1] + L);
    if (part.size() > 2)
    res = max(res, part[1] + part[2] + L + L);
    return res;
}

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

dreaming.cpp: In function 'void dfs2(int, int, int)':
dreaming.cpp:32:49: warning: ignoring return value of 'constexpr std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
   32 |         if (edge[node][i].first == par) suff[i+1]; = suff[i+2];
      |                                                 ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from dreaming.cpp:2:
/usr/include/c++/13/bits/stl_vector.h:1126:7: note: declared here
 1126 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
dreaming.cpp:32:52: error: expected primary-expression before '=' token
   32 |         if (edge[node][i].first == par) suff[i+1]; = suff[i+2];
      |                                                    ^
dreaming.cpp:33:9: error: 'else' without a previous 'if'
   33 |         else suff[i+1] = max(suff[i+2], dp[edge[node][i].first] + edge[node][i].second);
      |         ^~~~