Submission #892693

#TimeUsernameProblemLanguageResultExecution timeMemory
892693boxConstruction of Highway (JOI18_construction)C++17
7 / 100
18 ms1568 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...