이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |