답안 #282341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282341 2020-08-24T10:24:23 Z iliccmarko Traffic (IOI10_traffic) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

using namespace std;


long long dfs(int u, int pret, vector<vector<int> > g, long long &ans, int &ind, long long svi, int p[])
{
    long long br = 0;
    for(int i = 0;i<(int)g[u].size();i++)
    {
        int s = g[u][i];
        if(s==pret) continue;
        br+=dfs(s, u, g, ans, ind, svi, p);
    }

    if(br<ans)
    {
        ans = br;
        ind = u;
    }
    if(svi - br - p[u]<ans)
    {
        ans = svi - br - p[u];
        ind = u;
    }

    return br + p[u];
}

int LocateCenter(int n, ll p[], ll s[], ll d[])
{
    vector<vector<int> > g(1000);
    for(int i = 0;i<n-1;i++)
    {
        int a = s[i];
        int b = d[i];
        g[a].push_back(b);
        g[b].push_back(a);
    }
    long long svi = 0;
    for(int i = 0;i<n;i++)
    {
        svi+=p[i];
    }
    long long ans = LLONG_MAX;
    int ind;
    dfs(1, -1, g, ans, ind, svi, p);
    return ind;
}

Compilation message

traffic.cpp: In function 'int LocateCenter(int, long long int*, long long int*, long long int*)':
traffic.cpp:50:34: error: cannot convert 'long long int*' to 'int*'
   50 |     dfs(1, -1, g, ans, ind, svi, p);
      |                                  ^
      |                                  |
      |                                  long long int*
traffic.cpp:9:101: note:   initializing argument 7 of 'long long int dfs(int, int, std::vector<std::vector<int> >, long long int&, int&, long long int, int*)'
    9 | long long dfs(int u, int pret, vector<vector<int> > g, long long &ans, int &ind, long long svi, int p[])
      |                                                                                                 ~~~~^~~