#include "bits/stdc++.h"
using namespace std;
signed main () {
int n;
cin >> n;
vector <int> g[n], depth(n), parent(n);
map <pair <int,int>,int> edge;
function <void(int,int)> dfs=[&](int v, int p) {
if(p == -1) depth[v] = 0;
else depth[v] = depth[p] + 1;
parent[v] = p;
for(auto u : g[v]) {
if(p == u) continue;
dfs(u, v);
}
};
for(int i = 0; i < n - 1; i ++) {
int u, v;
cin >> u >> v;
u --, v --;
g[u].push_back(v);
g[v].push_back(u);
edge[{u, v}] = 0;
}
dfs(0, -1);
int k;
cin >> k;
vector <vector <int>> found;
while(k --) {
char ch;
cin >> ch;
// assert(ch == 'M');
int u, v, w;
cin >> u >> v >> w;
u --, v --;
found.push_back({u, v, w});
}
sort(found.begin(), found.end(), [](vector <int> a, vector <int> b){
return abs(a[0]-a[1]) < abs(b[0]-b[1]);
});
for(auto i : found) {
int u = i[0], v = i[1], w = i[2];
if(depth[u] > depth[v]) swap(u, v);
edge[{parent[v], v}] = w;
}
for(auto i : edge) {
cout << i.first.first + 1 << " " << i.first.second + 1 << " " << i.second << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
208 ms |
20648 KB |
Expected EOF |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
121 ms |
13560 KB |
Expected EOF |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |