1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
using namespace std;
long long int liczby[15000] = {};
long long int tabrazenia[15000] = {};
long long int tablica[15000][15000] = {};
int y, wym, x,p;
void licz(int y, int wym) {
	p = 0;
	for (int u = wym; u > 0; u--) {
		if (tablica[y][u] != 0) {
			if (tablica[y][u] <= tabrazenia[y]) {
				x++;
				liczby[p] = u;
				p++;
			}
		}
	}
}

int main() {
	long long int wym;
	cin >> wym;
	for (int z = 0; z < wym; z++) {
		cin >> tabrazenia[z];
	}
	for (int i = 0; i < wym - 1;i++) {
		int a, b, c;
		cin >> a >> b >> c;
		tablica[a - 1][b - 1] = c;
		tablica[b - 1][a - 1] = c;
	}
	for (int y = 0; y < wym; y++) {
		x = 1;
		p = 0;
		licz(y, wym);
		while (p != 0) {
			for (int r = 0; r < p; r++) {
				licz(liczby[r], wym);
			}
		}


		cout << x <<" "<<p<< endl;
	}
}