답안 #638621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638621 2022-09-06T14:21:10 Z ojoConmigo 꿈 (IOI13_dreaming) C++17
컴파일 오류
0 ms 0 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

vector<vector<pair<int,int>>> g;
vector<bool> visit;
vector<int> fir,sec,ans;
int x;

void dfs1(int nodo, int p){
    visit[nodo] = true;
    for(auto k : g[nodo]){
        int v = k.first;
        int w = k.second;
        if(v == p)continue;
        dfs1(v,nodo);
        if(fir[v] + w > fir[nodo]){
            sec[nodo] = fir[nodo];
            fir[nodo] = fir[v] + w;
        }else if(fir[v] + w > sec[nodo]){
            sec[nodo] = fir[v] + w;
        }
    }
}

int dfs2(int nodo, int p, int top){
    ans[nodo] = max(fir[nodo],top);
    int cont = ans[nodo];
    for(auto k : g[nodo]){
        int v = k.first;
        int w = k.second;
        if(v == p)continue;
        if(fir[v] + w == fir[nodo]) cont = min(cont,dfs2(v,nodo,max(top,sec[nodo]) + w));
        else cont = min(cont,dfs2(v,nodo,ans[nodo] + w));
    }
    return cont;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    g.resize(N);
    for(int i=0; i<M; i++){
        int x = A[i];
        int y = B[i];
        int w = T[i];
        g[x].push_back({y,w});
        g[y].push_back({x,w});
    }
    visit.assign(N,false);
    fir.assign(N,0);
    sec.assign(N,0);
    ans.resize(N);
    int m1,m2,m3;
    m1 = m2 = m3 = 0;
    for(int i=0; i<N; i++){
        if(visit[i] == false){
            dfs1(i,-1);
            int q = dfs2(i,-1,0);
            if(q > m1){
                m3 = m2;
                m2 = m1;
                m1 = q;
            }else if(q > m2){
                m3 = m2;
                m2 = q;
            }else if(q > m3){
                m3 = q;
            }
            //cout << i << " " << q << endl;
        }
    }
    return max(m1+m2+L,m2+m3+2*L);
}
/*
int main(){
    int n,m,l;
    cin >> n >> m >> l;
    int a[m],b[m],t[m];
    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i] >> t[i];
    }
    cout << travelTime(n,m,l,a,b,t) << endl;
}
*/

Compilation message

dreaming.cpp: In function 'void dfs1(int, int)':
dreaming.cpp:11:5: error: reference to 'visit' is ambiguous
   11 |     visit[nodo] = true;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from dreaming.cpp:2:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
dreaming.cpp:6:14: note:                 'std::vector<bool> visit'
    6 | vector<bool> visit;
      |              ^~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:48:5: error: reference to 'visit' is ambiguous
   48 |     visit.assign(N,false);
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from dreaming.cpp:2:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
dreaming.cpp:6:14: note:                 'std::vector<bool> visit'
    6 | vector<bool> visit;
      |              ^~~~~
dreaming.cpp:55:12: error: reference to 'visit' is ambiguous
   55 |         if(visit[i] == false){
      |            ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
                 from dreaming.cpp:2:
/usr/include/c++/10/variant:1700:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)'
 1700 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
dreaming.cpp:6:14: note:                 'std::vector<bool> visit'
    6 | vector<bool> visit;
      |              ^~~~~