This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#define INF LLONG_MAX
#define MOD 1000000007
#define endl "\n"
#define sp " "
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f1(i, x) for(auto &i : x)
#define f2(i, x, j) for(ll i = j; i < x; i++)
#define raya() cout << endl << "====================================" << endl
#define dbg(x) cerr << #x << ": " << x << endl;
using namespace std;
using ll = long long;
int sum = 0;
vector<vector<int>> sum1, sum2, arr;
vector<int> P;
vector<bool> vis;
ll dfs(int n){
if(vis[n]) return 0;
vis[n] = 1;
if(arr[n].size() == 1){
sum1[n].push_back(0);
sum1[n].push_back(sum - P[n]);
return P[n];
} else {
f1(i, arr[n]){
int aux;
aux = dfs(i);
if(aux){
sum1[n].push_back(aux);
}
}
}
int ans = 0;
f1(i, sum1[n]){
ans += i;
}
sum1[n].push_back(sum - ans - P[n]);
return ans + P[n];
}
int LocateCentre(int n, int p[], int s[], int d[]){
arr.assign(n, vector<int>(0));
sum1.assign(n, vector<int>(0));
sum2.assign(n, vector<int>(0));
f2(i, n, 0){
P.push_back(p[i]);
sum += P[i];
}
vis.assign(n, 0);
int r;
f2(i, n - 1, 0){
arr[s[i]].push_back(d[i]);
arr[d[i]].push_back(s[i]);
if(arr[s[i]].size() > 1){
r = s[i];
}
if(arr[d[i]].size() > 1){
r = d[i];
}
}
dfs(r);
int sans = -1, ans;
f2(i, n, 0){
int aux = 0;
f1(j, sum1[i]){
aux = max(j, aux);
}
if(sans == -1){
sans = aux;
ans = i;
}
if(sans > aux){
sans = aux;
ans = i;
}
}
return ans;
}
Compilation message (stderr)
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:84:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
84 | return ans;
| ^~~
traffic.cpp:68:8: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
68 | dfs(r);
| ~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |