답안 #414880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
414880 2021-05-31T09:59:15 Z snasibov05 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include "dreaming.h"
#include <vector>

using namespace std;

#define pb push_back
#define pii pair<int, int>
#define oo 1000000000

vector<vector<pii>> ed;
vector<bool> visited;
vector<int> mx;
vector<int> cur;

void dfs(int v){
    cur.pb(v);
    visited[v] = true;
    for (auto [x, t] : ed[v]){
        if (!visited[x]) dfs(x);
    }
}

int mxdist(int v, int pr){
    int res = 0;
    for (auto [x, t] : ed[v]){
        if (x != pr){
            res = max(res, mxdist(x, v) + t);
        }
    }

    return res;
}

void findmn(int v){

    cur.clear();
    dfs(v);

    int mn = oo;

    for (auto x : cur){
        int k = mxdist(x, -1);
        mn = min(mn, k);
    }

    mx.pb(mn);

}

int travelTime(int n, int m, int l, int a[], int b[], int t[]) {

    ed.resize(n);
    visited.resize(n);
    
    for (int i = 0; i < m; ++i) {
        ed[a[i]].pb({b[i], t[i]});
        ed[b[i]].pb({a[i], t[i]});
    }

    for (int i = 0; i < n; ++i) {
        if (!visited[i]) findmn(i);
    }

    sort(mx.rbegin(), mx.rend());
    
    if (mx.size() == 1) return mx[0];
    if (mx.size() == 2) return mx[0] + mx[1] + l;
    
    return max(mx[0] + mx[1] + l, mx[1] + mx[2] + 2*l);

}

Compilation message

dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:18:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   18 |     for (auto [x, t] : ed[v]){
      |               ^
dreaming.cpp: In function 'int mxdist(int, int)':
dreaming.cpp:25:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |     for (auto [x, t] : ed[v]){
      |               ^
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:64:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   64 |     sort(mx.rbegin(), mx.rend());
      |     ^~~~
      |     short