답안 #744312

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
744312 2023-05-18T11:53:40 Z bane 꿈 (IOI13_dreaming) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
const int maxN = (int)1e5 + 5;
#define ll long long
vector<vector<pair<ll,ll>>>adj(maxN);
ll vis[maxN], dist[maxN], parent[maxN];
ll mx = 0, source = -1;
ll ans = 0;
void dfs(ll u, ll p = -1, ll d = 0){
    vis[u] = 1;
    parent[u] = p;
    dist[u] = d;
    ans = max(ans, d);
    if (mx < d){
        mx = d;
        source = u;
    }
    for (auto x : adj[u]){
        if (x.first == p){
            continue;
        }
        dfs(x.first, u, x.second + d);
    }
}

ll travelTime(int N, int M, int L, int A[], int B[], int T[]){
    for (ll i = 0; i < M; i++){
        //cout<<A[i]<<" "<<B[i]<<endl;
        adj[A[i]].push_back({B[i], T[i]});
        adj[B[i]].push_back({A[i], T[i]});
    }
    vector<pair<ll,ll>>centroids;
    for (ll i = 0; i < N; i++){
        if (vis[i])continue;
        mx = -1, source = -1;
        dfs(i);
        ll S = source;
        mx = -1;
        dfs(S);
        ll E = source;
        vector<pair<ll,ll>>path;
       // cout<<S<<" "<<E<<endl;
        while(E != S){
            path.push_back({E, dist[E]});
            E = parent[E];
        }
        path.push_back({E, dist[E]});
        reverse(path.begin(), path.end());
        ll diameter = path.back().second;
        ll best_node = path[0].first, best_dist = 1e18;
        for(ll j = 0; j < path.size(); j++){
            if(max(path[j].second, diameter - path[j].second) < best_dist){
                best_node = path[j].first;
                best_dist = max(path[j].second, diameter - path[j].second);
            }
        }
        centroids.push_back({best_dist, best_node});
    }
   // for (auto j  : centroids)cout<<j.first<<" "<<j.second<<endl;
    sort(centroids.rbegin(), centroids.rend());
    if (centroids.size() > 2)ans = max(ans, L + centroids[0].first + centroids[1].first);
    if (centroids.size() > 3)ans = max(ans, L * 2 + centroids[1].first + centroids[2].first);
    return ans;
}


Compilation message

dreaming.cpp:27:4: error: ambiguating new declaration of 'long long int travelTime(int, int, int, int*, int*, int*)'
   27 | ll travelTime(int N, int M, int L, int A[], int B[], int T[]){
      |    ^~~~~~~~~~
In file included from dreaming.cpp:2:
dreaming.h:8:5: note: old declaration 'int travelTime(int, int, int, int*, int*, int*)'
    8 | int travelTime(int N, int M, int L, int A[], int B[], int T[]);
      |     ^~~~~~~~~~
dreaming.cpp: In function 'long long int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:52:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(ll j = 0; j < path.size(); j++){
      |                       ~~^~~~~~~~~~~~~