답안 #372417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372417 2021-02-28T04:13:53 Z MaisyDoge13 Traffic (IOI10_traffic) C++17
0 / 100
2 ms 492 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 j=0;j<(roads.size());j++) {
            res=max(roads[j].first, res);
        }
        return res;
    }
};
vector<shared_ptr<City>> cities;
int LocateCentre(int n_cities, int p_arr[], int d_arr[], int s_arr[]) {

    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 = p_arr[i];
        cities.push_back(make_shared<City>(i, p));
    }
    for (int i=0;i<n-1;i++) {
        int a=d_arr[i], b=s_arr[i];
        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 j=0;j<(roads.size());j++) {
      |                      ~^~~~~~~~~~~~~~~
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:73:1: warning: no return statement in function returning non-void [-Wreturn-type]
   73 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -