답안 #347943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
347943 2021-01-13T21:43:10 Z isym444 Traffic (IOI10_traffic) C++17
컴파일 오류
0 ms 0 KB
#include "traffic.h"
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <iostream>

using namespace std;
/* using std::vector; */

#define fo(i, n) for (i = 0; i < n; i++)

#define ll long long
#define sz(x) (int)(x).size()
#define mp make_pair
typedef pair<ll, ll> pl;

#define pb push_back


/* void setIO(string name = "")
{ // name is nonempty for USACO file I/O
    ios_base::sync_with_stdio(0);
    cin.tie(0); // see Fast Input & Output
    // alternatively, cin.tie(0)->sync_with_stdio(0);
    if (sz(name))
    {
        freopen((name + ".in").c_str(), "r", stdin); // see Input & Output
        freopen((name + ".out").c_str(), "w", stdout);
    }
} */
// -----------------------------
const int MX = 1000;
const int INF = 2e9 + 1;

int fans = 0;

vector<int> g[MX], nodes(MX), people(MX), children(MX);
int p[MX];

void dfs (int v, int parent) {

}


int LocateCentre (int n) {
    //h cycle through tree p, selecting each node to be root
    //h for each tree, do dfs, finding minimum max value of sums of subtrees
    int curmax;
    int totalmin=INF;
    int ans;
    for(int i = 0; i<n; i++)
    {
        int ls=0;
        int rs=0;
        for(int k = 0; k<i; k++)
        {
            ls+=p[k];
        }
        for(int t = i+1; t<=n-1; t++)
        {
            rs+=p[t];
        }
        curmax=max(ls,rs);
        if(curmax<totalmin)
        {
            totalmin=curmax;
            ans=i;
        }
    }
    //cout << ans;
    return ans;
}

/* int main ()
{
    ios_base::sync_with_stdio(0);
    setIO("cpp");
    int n;
    cin >> n;
    for(int i = 0; i<n; i++)
    {
        cin >> p[i];
    }
    LocateCentre(n);
} */

//h populations of cities 0-3: 1 1 1 1000
//h cities joined by roads as follows: 0->1->2->3

Compilation message

traffic.cpp: In function 'int LocateCentre(int)':
traffic.cpp:73:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   73 |     return ans;
      |            ^~~
/tmp/ccaMjX0g.o: In function `main':
grader.cpp:(.text.startup+0xd9): undefined reference to `LocateCentre(int, int*, int*, int*)'
collect2: error: ld returned 1 exit status