답안 #648779

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648779 2022-10-08T09:52:11 Z LouayFarah 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include "bits/stdc++.h"

using namespace std;

#define endl "\n"
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second


const long long MOD = 1e9+7;
const long long INF = 1e18;

int nx[8] = {0, 0, -1, 1, 1, -1, 1, -1};
int ny[8] = {1, -1, 0, 0, -1, 1, 1, -1};

void dfs(vector<pair<ll, ll>> adj[], int u, vector<bool> &visited, vector<ll> &curr_comp)
{
    if(visited[u])
        return;
    visited[u] = true;

    for(auto v: adj[u])
    {
        dfs(adj, v.fi, visited, curr_comp);
    }
}

void dfs_dist(vector<pair<ll, ll>> adj[], ll u, ll p, vector<int> &dist)
{
    for(auto v: adj[u])
    {
        if(v.fi!=p)
        {
            dist[v.fi] = dist[u] + v.se;
            dfs_dist(adj, v.fi, u, dist);
        }
    }
}

int calculate_diameter(vector<pair<ll, ll>> adj[], int N)
{
    int a = 1;
    vector<int> dist_a(N+1, 0);
    dfs_dist(adj, a, -1, dist_a);

    int b = -1;
    int maximum_a = 0;

    for(int i = 1; i<=N; i++)
    {
        if(dist_a[i]>maximum_a)
        {
            maximum_a = dist_a[i];
            b = i;
        }
    }

    vector<int> dist_b(N+1, 0);
    dfs_dist(adj, b, -1, dist_b);

    int c = -1;
    int maximum_b = 0;
    for(int i = 1; i<=N; i++)
    {
        if(dist_b[i]>maximum_b)
        {
            maximum_b = dist_b[i];
            c = i;
        }
    }

    return dist_b[c];
}

int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
    //creating the graph
    vector<pair<ll, ll>> adj[N+1];
    for(int i = 0; i<M; i++)
    {
        adj[A[i]+1].pb(mp(B[i]+1, T[i]));
        adj[B[i]+1].pb(mp(A[i]+1, T[i]));
    }


    //extracting the 2 components
    vector<vector<ll>> comps;
    vector<bool> visited(N+1, false);
    for(int u = 1; u<=N; u++)
    {
        if(visited[u])
            continue;
        vector<ll> curr_comp;
        dfs(adj, u, visited, curr_comp);

        comps.pb(curr_comp);
    }


    int res = 1e9;
    for(int i = 0; i<int(comps[0].size()); i++)
    {
        for(int j = 0; j<int(comps[1].size()); j++)
        {
            //adding the edge
            adj[comps[0][i]].pb(mp(comps[1][j], L));
            adj[comps[1][j]].pb(mp(comps[0][i], L));

            //Calculating tree diameter
            int diameter = calculate_diameter(adj, N);

            res = min(res, diameter);
        }
    }

    return res;
}

Compilation message

/usr/bin/ld: /tmp/cchSqrcu.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status