This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define sz(v) int(std::size(v))
using i64 = long long;
using pii = pair<int, int>;
const int N = 500;
int n, c[N];
vector<int> adj[N];
vector<int> path[N];
vector<pii> con;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 0; i < n; i++) cin >> c[i];
for (int h = 0; h < n - 1; h++) {
int i, j;
cin >> i >> j, i--, j--;
adj[i].push_back(j);
adj[j].push_back(i);
con.push_back({i, j});
}
path[0] = {0};
for (auto [i, j] : con) {
path[j] = path[i];
path[j].push_back(j);
int cost = 0;
for (int x = 0; x < sz(path[i]); x++) for (int y = x + 1; y < sz(path[i]); y++)
cost += c[path[i][x]] > c[path[i][y]];
for (int v : path[j]) c[v] = c[j];
cout << cost << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |