Submission #406559

#TimeUsernameProblemLanguageResultExecution timeMemory
406559benkTraffic (IOI10_traffic)C++14
Compilation error
0 ms0 KiB
#include "traffic.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;

int tot;
vector<int> adj[N], ch(N), peop(N), curr(N);
vector<bool> vis(N);
void dfs(int x) {
	vis[x] = 1;
	for (auto it : adj[x]) {
		if (vis[it]) continue;
		dfs(it);
		ch[x] += ch[it];
		peop[x] = max(peop[x], ch[x]); // max of all ch
	}
	ch[x] += curr[x];
	peop[x] = max(peop[x], tot - ch[x]); // either from par or ch
}

int LocateCentre(int n, int p[], int s[], int d[]) {
	for (int i = 0; i < n - 1; i++) {
		adj[s[i]].pb(d[i]);
		adj[d[i]].pb(s[i]);
	}

	for (int i = 0; i < n; i++) {
		tot += p[i];
		curr[i] = p[i];
	}
	dfs(0);
	int ans = INT_MAX, res = -1;
	for (int i = 0; i < n; i++) {
		if (ans > peop[i]) {
			ans = peop[i];
			res = i;
		}
	}

	return res;
}

Compilation message (stderr)

traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:24:13: error: 'class std::vector<int>' has no member named 'pb'
   24 |   adj[s[i]].pb(d[i]);
      |             ^~
traffic.cpp:25:13: error: 'class std::vector<int>' has no member named 'pb'
   25 |   adj[d[i]].pb(s[i]);
      |             ^~