(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #372422

#TimeUsernameProblemLanguageResultExecution timeMemory
372422MaisyDoge13Traffic (IOI10_traffic)C++17
100 / 100
1605 ms231148 KiB
#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); n=n_cities; 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]; 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; } } return city; }

Compilation message (stderr)

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++) {
      |                      ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...