Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n, m;
- vector<int> G[200];
- int level[200], father[200], color[200];
- void dfs(int v, int p, int d) {
- father[v] = p;
- level[v] = d;
- for(int &u : G[v])
- if(u != p)
- dfs(u, v, d + 1);
- }
- void paint(int u, int v, int c) {
- while(u != v) {
- color[u] = c;
- color[v] = c;
- if(level[u] > level[v])
- u = father[u];
- else
- v = father[v];
- }
- color[u] = c;
- }
- int32_t main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cin >> n >> m;
- for(int i = 1; i < n; i++) {
- int u, v;
- cin >> u >> v; v--; u--;
- G[u].push_back(v);
- G[v].push_back(u);
- }
- dfs(0, -1, 0);
- while(m--) {
- int u, v, c;
- cin >> u >> v >> c; u--; v--;
- paint(u, v, c);
- }
- for(int i = 0; i < n; i++)
- cout << color[i] << ' ';
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement