Submission #1355034

#TimeUsernameProblemLanguageResultExecution timeMemory
1355034thuhienneTransport (COCI19_transport)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define re exit(0);

int n,fuel[maxn];
vector <pair <int,int>> adj[maxn];

ll res;
int sz[maxn];
bool del[maxn];

int countChild(int node,int par) {
	sz[node] = 1;
	for (int x : adj[node]) if (x.first != par && !del[x.first]) {
		sz[node] += countChild(x.first,node);
	}
	
	return sz[node];
}
int findCentroid(int node,int par,int n) {
	for (int x : adj[node]) if (x.first != par && !del[x.first] && sz[x.first] > n / 2) {
		return findCentroid(x.first,node,n);
	}
	return node;
}

//0:up,1:down
vector <pair <ll,bool>> cont[maxn];

void solve(int node) {

	for (int x : adj[node]) if (!del[x.first]) {
		int child = x.first,w = x.second;
		
		if (fuel[child] >= w) cont[child].push_back({fuel[child] - w + fuel[node]});
	}

}

void solve(int node) {
	int cnt = countChild(node,0);
	int ct = findCentroid(node,0,cnt);
	
	solve(ct);
	
	del[ct] = 1;
	for (int x : adj[node]) if (!del[x.first]) solve(x.first);
	
}

int main() {
//  ios_base::sync_with_stdio(0);
//  cin.tie(nullptr);
//  freopen(".inp","r",stdin);
//  freopen(".out","w",stdout);

	cin >> n;
	for (int i = 1;i <= n;i++) cin >> fuel[i];
	for (int i = 1;i < n;i++) {
		int u,v,w;cin >> u >> v >> w;
		adj[u].push_back({v,w});
		adj[v].push_back({u,w});
	}
	
	solve(1);

}

Compilation message (stderr)

Main.cpp:8:12: error: 'maxn' was not declared in this scope
    8 | int n,fuel[maxn];
      |            ^~~~
Main.cpp:9:29: error: 'maxn' was not declared in this scope
    9 | vector <pair <int,int>> adj[maxn];
      |                             ^~~~
Main.cpp:12:8: error: 'maxn' was not declared in this scope
   12 | int sz[maxn];
      |        ^~~~
Main.cpp:13:10: error: 'maxn' was not declared in this scope
   13 | bool del[maxn];
      |          ^~~~
Main.cpp: In function 'int countChild(int, int)':
Main.cpp:16:9: error: 'sz' was not declared in this scope
   16 |         sz[node] = 1;
      |         ^~
Main.cpp:17:22: error: 'adj' was not declared in this scope
   17 |         for (int x : adj[node]) if (x.first != par && !del[x.first]) {
      |                      ^~~
Main.cpp:17:39: error: request for member 'first' in 'x', which is of non-class type 'int'
   17 |         for (int x : adj[node]) if (x.first != par && !del[x.first]) {
      |                                       ^~~~~
Main.cpp:17:56: error: 'del' was not declared in this scope
   17 |         for (int x : adj[node]) if (x.first != par && !del[x.first]) {
      |                                                        ^~~
Main.cpp:17:62: error: request for member 'first' in 'x', which is of non-class type 'int'
   17 |         for (int x : adj[node]) if (x.first != par && !del[x.first]) {
      |                                                              ^~~~~
Main.cpp:18:42: error: request for member 'first' in 'x', which is of non-class type 'int'
   18 |                 sz[node] += countChild(x.first,node);
      |                                          ^~~~~
Main.cpp: In function 'int findCentroid(int, int, int)':
Main.cpp:24:22: error: 'adj' was not declared in this scope
   24 |         for (int x : adj[node]) if (x.first != par && !del[x.first] && sz[x.first] > n / 2) {
      |                      ^~~
Main.cpp:24:39: error: request for member 'first' in 'x', which is of non-class type 'int'
   24 |         for (int x : adj[node]) if (x.first != par && !del[x.first] && sz[x.first] > n / 2) {
      |                                       ^~~~~
Main.cpp:24:56: error: 'del' was not declared in this scope
   24 |         for (int x : adj[node]) if (x.first != par && !del[x.first] && sz[x.first] > n / 2) {
      |                                                        ^~~
Main.cpp:24:62: error: request for member 'first' in 'x', which is of non-class type 'int'
   24 |         for (int x : adj[node]) if (x.first != par && !del[x.first] && sz[x.first] > n / 2) {
      |                                                              ^~~~~
Main.cpp:24:72: error: 'sz' was not declared in this scope
   24 |         for (int x : adj[node]) if (x.first != par && !del[x.first] && sz[x.first] > n / 2) {
      |                                                                        ^~
Main.cpp:24:77: error: request for member 'first' in 'x', which is of non-class type 'int'
   24 |         for (int x : adj[node]) if (x.first != par && !del[x.first] && sz[x.first] > n / 2) {
      |                                                                             ^~~~~
Main.cpp:25:39: error: request for member 'first' in 'x', which is of non-class type 'int'
   25 |                 return findCentroid(x.first,node,n);
      |                                       ^~~~~
Main.cpp: At global scope:
Main.cpp:31:30: error: 'maxn' was not declared in this scope
   31 | vector <pair <ll,bool>> cont[maxn];
      |                              ^~~~
Main.cpp: In function 'void solve(int)':
Main.cpp:35:22: error: 'adj' was not declared in this scope
   35 |         for (int x : adj[node]) if (!del[x.first]) {
      |                      ^~~
Main.cpp:35:38: error: 'del' was not declared in this scope
   35 |         for (int x : adj[node]) if (!del[x.first]) {
      |                                      ^~~
Main.cpp:35:44: error: request for member 'first' in 'x', which is of non-class type 'int'
   35 |         for (int x : adj[node]) if (!del[x.first]) {
      |                                            ^~~~~
Main.cpp:36:31: error: request for member 'first' in 'x', which is of non-class type 'int'
   36 |                 int child = x.first,w = x.second;
      |                               ^~~~~
Main.cpp:38:21: error: 'fuel' was not declared in this scope
   38 |                 if (fuel[child] >= w) cont[child].push_back({fuel[child] - w + fuel[node]});
      |                     ^~~~
Main.cpp:38:36: error: 'w' was not declared in this scope
   38 |                 if (fuel[child] >= w) cont[child].push_back({fuel[child] - w + fuel[node]});
      |                                    ^
Main.cpp:38:39: error: 'cont' was not declared in this scope; did you mean 'const'?
   38 |                 if (fuel[child] >= w) cont[child].push_back({fuel[child] - w + fuel[node]});
      |                                       ^~~~
      |                                       const
Main.cpp: At global scope:
Main.cpp:43:6: error: redefinition of 'void solve(int)'
   43 | void solve(int node) {
      |      ^~~~~
Main.cpp:33:6: note: 'void solve(int)' previously defined here
   33 | void solve(int node) {
      |      ^~~~~
Main.cpp: In function 'void solve(int)':
Main.cpp:49:9: error: 'del' was not declared in this scope
   49 |         del[ct] = 1;
      |         ^~~
Main.cpp:50:22: error: 'adj' was not declared in this scope
   50 |         for (int x : adj[node]) if (!del[x.first]) solve(x.first);
      |                      ^~~
Main.cpp:50:44: error: request for member 'first' in 'x', which is of non-class type 'int'
   50 |         for (int x : adj[node]) if (!del[x.first]) solve(x.first);
      |                                            ^~~~~
Main.cpp:50:60: error: request for member 'first' in 'x', which is of non-class type 'int'
   50 |         for (int x : adj[node]) if (!del[x.first]) solve(x.first);
      |                                                            ^~~~~
Main.cpp: In function 'int main()':
Main.cpp:61:43: error: 'fuel' was not declared in this scope
   61 |         for (int i = 1;i <= n;i++) cin >> fuel[i];
      |                                           ^~~~
Main.cpp:64:17: error: 'adj' was not declared in this scope
   64 |                 adj[u].push_back({v,w});
      |                 ^~~