답안 #345547

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
345547 2021-01-07T14:46:49 Z 79brue 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m, k;
vector<pair<int, int> > link[100002];
int DP[100002], DP2[100002];
bool visited[100002];
int ans;

int minVal;
vector<int> vec;

void dfs(int x){
    visited[x] = 1;
    for(auto y: link[x]){
        if(visited[y.first]) continue;
        dfs(y.first);

        int tmp1 = DP[y.first] + y.second;
        int tmp2 = DP2[y.first] + y.second;
        if(DP2[x] < tmp1) DP2[x] = tmp1;
        if(DP2[x] > DP[x]) swap(DP[x], DP2[x]);
        if(DP2[x] < tmp2) DP2[x] = tmp2;
    }
    if(DP[x] < 0) DP[x] = 0;
    ans = max(ans, DP[x] + DP2[x]);
    visited[x] = 0;
}
void dfs2(int x, int fromUp){
    visited[x] = 1;
    minVal = min(minVal, max(fromUp, DP[x]));
    for(auto y: link[x]){
        if(visited[y.first]) continue;
        dfs2(y.first, max(fromUp, (DP[x] == DP[y.first] + y.second) ? DP2[x] : DP[x]) + y.second);
    }
}

int main(){
    scanf("%d %d %d", &n, &m, &k);
    for(int i=1; i<=n; i++) DP[i] = DP2[i] = -1e9;
    for(int i=1; i<=m; i++){
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        link[x].push_back(make_pair(y, z));
        link[y].push_back(make_pair(x, z));
    }

    for(int i=0; i<n; i++){
        if(!visited[i]){
            minVal = INT_MAX;
            dfs(i);
            dfs2(i, 0);
            vec.push_back(minVal);
        }
    }
    sort(vec.rbegin(), vec.rend());
    if(vec.size() >= 2) ans = max(ans, vec[0] + k + vec[1]);
    if(vec.size() >= 3) ans = max(ans, vec[1] + k + k + vec[2]);
    printf("%d", ans);
}

Compilation message

dreaming.cpp: In function 'int main()':
dreaming.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |     scanf("%d %d %d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |         scanf("%d %d %d", &x, &y, &z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/tmp/ccH3vdO8.o: In function `main':
dreaming.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc48zBhN.o:grader.c:(.text.startup+0x0): first defined here
/tmp/cc48zBhN.o: In function `main':
grader.c:(.text.startup+0xc9): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status