Submission #372414

# Submission time Handle Problem Language Result Execution time Memory
372414 2021-02-28T04:07:57 Z MaisyDoge13 Traffic (IOI10_traffic) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <array>
#include <set>
#include <climits>
#include <map>
#include <memory>
using namespace std;

#define input "problem.in"
#define output "problem.out"
int n;
struct City {
    int i, p;
    bool vis=0;
    vector<pair<int,shared_ptr<City>>> roads;
    City(int I, int P) {
        i=I; p=P;
    }
    int DFS(int prev=-1) {
        int added=p;
        for (int j=0;j<roads.size();j++) {
            if (roads[j].second->i==prev) continue;
            if (roads[j].first==0) {
                roads[j].first=roads[j].second->DFS(i);
            }
            added+=roads[j].first;
        }
        return added;
    }
    int res() {
        int res=0;
        for (int i=0;i<roads.size();i++) {
            res=max(roads[i].first, res);
        }
        return res;
    }
};
vector<shared_ptr<City>> cities;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen(input, "r", stdin);
    //freopen(output, "w", stdout);
    cin >> n; cities.reserve(n);
    for (int i=0;i<n;i++) {
        int p; cin >> p;
        cities.push_back(make_shared<City>(i, p));
    }
    for (int i=1;i<n;i++) {
        int a, b;
        cin >> a >> b;
        cities[a]->roads.push_back({0,cities[b]});
        cities[b]->roads.push_back({0,cities[a]});
    }
    int ans=INT_MAX;
    int city=0;
    for (shared_ptr<City> c: cities) {
        c->DFS();
    }
    for (shared_ptr<City> c: cities) {
        int res=c->res();
        if (res < ans) {
            ans = res;
            city=c->i;
        }
    }
    cout << city << endl;
}

Compilation message

traffic.cpp: In member function 'int City::DFS(int)':
traffic.cpp:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::shared_ptr<City> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (int j=0;j<roads.size();j++) {
      |                      ~^~~~~~~~~~~~~
traffic.cpp: In member function 'int City::res()':
traffic.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::shared_ptr<City> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for (int i=0;i<roads.size();i++) {
      |                      ~^~~~~~~~~~~~~
/tmp/ccY88ITn.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccqg4nI5.o:traffic.cpp:(.text.startup+0x0): first defined here
/tmp/ccY88ITn.o: In function `main':
grader.cpp:(.text.startup+0xd9): undefined reference to `LocateCentre(int, int*, int*, int*)'
collect2: error: ld returned 1 exit status