Submission #1137074

#TimeUsernameProblemLanguageResultExecution timeMemory
1137074arijit_biswasTraffic (IOI10_traffic)C++20
Compilation error
0 ms0 KiB
#include "traffic.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long

vector<vector<int>> g;
vector<int> subtreeSum;

void dfs(int node, int par) {
	subtreeSum[node] = p[node];
	for (auto &v : g[node]) {
		if (v != par) {
			dfs(v, node);
			subtreeSum[node] += subtreeSum[v];
		}
	}
}

bool check(int x, int n) {
	int maxTraffic = 1e9;
	for (int i = 0; i < n; i++) {
		int temp = 0;
		for (auto &v : g[i]) {
			subtreeSum.assign(n, 0);
			dfs(v, i);
			// for (auto &x : subtreeSum) {
			// 	cout << x << " ";
			// }
			// cout << " -> " << subtreeSum[v] << endl;
			temp = max(temp, subtreeSum[v]);
		}
		maxTraffic = min(maxTraffic, temp);
		// cout << endl;
	}
	return maxTraffic <= x;
}

int LocateCentre(int n, int p[], int s[], int d[]) {
	g.resize(n);
	for (int i = 0; i < n - 1; i++) {
		g[s[i]].push_back(d[i]);
		g[d[i]].push_back(s[i]);
	}
	int low = 1, high = 1000, ans = high;
	while (low <= high) {
		int mid = low + (high - low) / 2;
		if (check(mid, n)) {
			ans = mid;
			high = mid - 1;
		} else {
			low = mid + 1;
		}
	}
	return ans;
}
#undef int

Compilation message (stderr)

traffic.cpp: In function 'void dfs(long long int, long long int)':
traffic.cpp:10:28: error: 'p' was not declared in this scope
   10 |         subtreeSum[node] = p[node];
      |                            ^