-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path192E.cpp
127 lines (112 loc) · 2.26 KB
/
192E.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <stack>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#include <stdio.h>
#define MOD 1000000007
#define exit return 0
#define inf 10000000000
#define exit return 0
#define PS system("pause")
#define S 100007
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left (v<<1)
#define right (left|1)
#define mid ((tl+tr)>>1)
#define SZ(x) ((int)x.size())
const double eps = 1e-10;
using namespace std;
using ll = long long;
using ul = unsigned long long;
using PII = pair<int, int>;
const int NN = 100002;
const int NZ = 111000;
const int MM = 151;
const int mask = 1 << 4;
const int need = (1 << 30) - 1;
vector<int>gr[NN];
int up[NN][25];
int n, k, m, s, x, a, b, c, q;
int dp[322][322], tin[NN], tout[NN], timer, cc[NN];
map<PII, int>fx;
int cur[NN];
int answww[NN];
#define MX(a,b)a>b?a:b
void doit(int v, int p = 1){
up[v][0] = p;
tin[v] = ++timer;
for (int i = 1; i <= 20; i++){
up[v][i] = up[up[v][i - 1]][i - 1];
}
for (int i = 0; i < gr[v].size(); i++){
int to = gr[v][i];
if (to != p){
doit(to, v);
}
}
tout[v] = ++timer;
}
bool is_child(int a, int b){
return (tin[a] <= tin[b] && tout[a] >= tout[b]);
}
int lca(int a, int b){
if (is_child(a, b))return a;
if (is_child(b, a))return b;
for (int i = 20; i >= 0; i--){
if (!is_child(up[a][i], b)){
a = up[a][i];
}
}
return up[a][0];
}
void dfs(int v, int p = -1){
for (auto x : gr[v]){
if (x != p){
dfs(x, v);
cc[v] += cc[x];
int ff = min(v, x);
int se = max(v, x);
answww[fx[{ff, se}]] = cc[x];
}
}
}
int main(){
scanf("%d", &n);
for (int i = 1; i <= n - 1; i++){
scanf("%d %d", &a, &b);
gr[a].push_back(b);
gr[b].push_back(a);
if (a > b)swap(a, b);
fx[{a, b}] = i;
}
doit(1);
scanf("%d", &m);
for (int i = 1; i <= m; i++){
scanf("%d %d", &a, &b);
cc[a] += 1; cc[b] += 1;
cc[lca(a, b)] -= 2;
}
dfs(1);
for (int i = 1; i < n; i++){
printf("%d\n", answww[i]);
}
exit;
}