Submission #393361

# Submission time Handle Problem Language Result Execution time Memory
393361 2021-04-23T09:59:59 Z huukhang Traffic (IOI10_traffic) C++11
Compilation error
0 ms 0 KB
// - Only when necessary :d
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")

// #include "traffic.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fileopen(a, b) freopen(((string)a + ".inp").c_str(), "r", stdin); freopen(((string)b + ".out").c_str(), "w", stdout); 

#define ll long long
#define int long long
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const double eps = 1e-9;

int sum = 0;
int a[1000005];
vector<vector<int>> g;
int sz[1000005], congest[1000005];

void dfs(int s, int p) {
	for (auto v : g[s]) {
		if (v != p) {
			dfs(v, s);
			sz[s] += sz[v];
			congest[s] = max(congest[s], congest[v]);
		}
	}

	congest[s] = max(congest[s], sum - sz[s] - a[s]);
	sz[s] += a[s];
}

int LocateCentre(int n, int p[], int s[], int d[]) {
	for (int i = 0; i < n; ++i) a[i] = p[i];

	g.resize(n + 5);
	for (int i = 0; i < n - 1; ++i) {
		g[s[i]].pb(d[i]);
		g[d[i]].pb(s[i]);
	}

	for (int i = 0; i < n; ++i) sum += a[i];

	dfs(0, -1);

	int mn = inf, ans;
	for (int i = 0; i < n; ++i) {
		if (mn > congest[i]) {
			mn = congest[i];
			ans = i;
		}
	}

	return ans;
}

Compilation message

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