#include <bits/stdc++.h>
using namespace std;
int n,e,a[300001],b[300001],r,mst[300001],p[300001],d[300001],l[300001],id,res[300001];
vector <int> ke[300001],ve;
int f(int i){
return (l[i]==i?i:l[i]=f(l[i]));
}
void unite(int i, int j){
l[f(j)]=f(i);
}
void dfs(int u, int par){
for (int i:ke[u]){
int v=a[i]^b[i]^u;
if (v!=par){
p[v]=i;
d[v]=d[u]+1;
dfs(v,u);
}
}
}
void walk(int u, int v){
ve.clear();
while (true){
u=f(u);
v=f(v);
if (u==v)
break;
if (d[u]<d[v])
swap(u,v);
int i=p[u];
unite(a[i]^b[i]^u,u);
ve.push_back(i);
}
sort(ve.begin(),ve.end());
for (int i:ve)
res[i]=++id;
}
int main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n >> e;
for (int i=1;i<=e;i++)
cin >> a[i] >> b[i];
for (int i=1;i<n;i++){
cin >> r;
mst[r]=1;
ke[a[r]].push_back(r);
ke[b[r]].push_back(r);
}
iota(l,l+n+1,0);
dfs(1,1);
for (int i=1;i<=e;i++){
if (!res[i]){
walk(a[i],b[i]);
if (!res[i])
res[i]=++id;
}
cout << res[i] << ' ';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
13092 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
13092 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Correct |
4 ms |
12892 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
3 ms |
12892 KB |
Output is correct |
7 |
Correct |
3 ms |
12892 KB |
Output is correct |
8 |
Correct |
3 ms |
12892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
20432 KB |
Output is correct |
2 |
Correct |
57 ms |
23544 KB |
Output is correct |
3 |
Correct |
55 ms |
19032 KB |
Output is correct |
4 |
Correct |
102 ms |
30992 KB |
Output is correct |
5 |
Correct |
94 ms |
31948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
28364 KB |
Output is correct |
2 |
Correct |
35 ms |
18768 KB |
Output is correct |
3 |
Correct |
19 ms |
15964 KB |
Output is correct |
4 |
Correct |
44 ms |
24668 KB |
Output is correct |
5 |
Correct |
18 ms |
16988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
38600 KB |
Output is correct |
2 |
Correct |
146 ms |
43892 KB |
Output is correct |
3 |
Correct |
33 ms |
22736 KB |
Output is correct |
4 |
Correct |
49 ms |
26452 KB |
Output is correct |
5 |
Correct |
223 ms |
43520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
31976 KB |
Output is correct |
2 |
Correct |
56 ms |
26708 KB |
Output is correct |
3 |
Correct |
209 ms |
38996 KB |
Output is correct |
4 |
Correct |
183 ms |
36476 KB |
Output is correct |
5 |
Correct |
14 ms |
14428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
13092 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Correct |
4 ms |
12892 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
3 ms |
12892 KB |
Output is correct |
7 |
Correct |
3 ms |
12892 KB |
Output is correct |
8 |
Correct |
3 ms |
12892 KB |
Output is correct |
9 |
Correct |
33 ms |
20432 KB |
Output is correct |
10 |
Correct |
57 ms |
23544 KB |
Output is correct |
11 |
Correct |
55 ms |
19032 KB |
Output is correct |
12 |
Correct |
102 ms |
30992 KB |
Output is correct |
13 |
Correct |
94 ms |
31948 KB |
Output is correct |
14 |
Correct |
61 ms |
28364 KB |
Output is correct |
15 |
Correct |
35 ms |
18768 KB |
Output is correct |
16 |
Correct |
19 ms |
15964 KB |
Output is correct |
17 |
Correct |
44 ms |
24668 KB |
Output is correct |
18 |
Correct |
18 ms |
16988 KB |
Output is correct |
19 |
Correct |
143 ms |
38600 KB |
Output is correct |
20 |
Correct |
146 ms |
43892 KB |
Output is correct |
21 |
Correct |
33 ms |
22736 KB |
Output is correct |
22 |
Correct |
49 ms |
26452 KB |
Output is correct |
23 |
Correct |
223 ms |
43520 KB |
Output is correct |
24 |
Correct |
95 ms |
31976 KB |
Output is correct |
25 |
Correct |
56 ms |
26708 KB |
Output is correct |
26 |
Correct |
209 ms |
38996 KB |
Output is correct |
27 |
Correct |
183 ms |
36476 KB |
Output is correct |
28 |
Correct |
14 ms |
14428 KB |
Output is correct |
29 |
Correct |
180 ms |
37140 KB |
Output is correct |
30 |
Correct |
213 ms |
36420 KB |
Output is correct |
31 |
Correct |
170 ms |
33492 KB |
Output is correct |
32 |
Correct |
58 ms |
19456 KB |
Output is correct |
33 |
Correct |
185 ms |
33956 KB |
Output is correct |