Rank Tên đăng nhập Điểm Bài tập Giới thiệu
20301 80 1
20302 0 0
20303 1260 3
20304 0 0
20305 2805 7
20306 216 1
20307 0 0
20308 101 1
20308 101 1
20310 201 1
20311 0 0
20312 801 1
20312 801 1
20314 0 0
20314 0 0
20316
daon5880
Call Me Nguyên
21027 370

Toán,Lí,Hóa... em cthe chiến thắng tất cả, chỉ thua cuộc trước Anh.

20317 0 0

<><>

20317 0 0
20319 1173 3
20320 2001 1
20321 412 4
20322 392 2
20323 0 0

Ư3GER

20323 0 0
20325
neko_chan
Nguyễn Đặng Quỳnh Như
2330 25
while "i"<3*"u": 
 print("je t'aime tame")

01110100 01100001 01101101 01100101 00101011 01101110 01100101 01101011 01101111 00111101 01110100 01100001 01101011 01101111

20326 0 0
20327
Tranngocson2006
Trần Ngọc Sơn
8017 70
20328 1601 1
20329 822 2
20330 13751 53

manhmit

20331 1157 5
20332 0 0
20332 0 0
20334
longdegea11
No brain user
16551 262

Welcome to my profile. Feel free to take a look at it.

20335 0 0
20335 0 0
20337 2722 21
20338 2839 5
20339 801 1
20340 6624 103
20341 535 6
20342
datp3877
Phan Thanh Đạt
7309 13
20343 4654 4

include<bits/stdc++.h>

using namespace std;

define endl "\n"

define pb push_back

define ll long long

const int maxn=1e6+1;

vector<int>adj[maxn],queries[maxn];
int n,q,par[maxn],rnk[maxn],ancestor[maxn];
bool visited[maxn];
map<pair\<int,int>,int>mp;
vector<pair\<int,int>>ans;

int find_set(int u){
while(par[u]!=u)u=par[u];
return u;
}

void union_set(int x,int y){
int xroot=find_set(x);
int yroot=find_set(y);
if(xroot==yroot)return;
if(rnk[xroot]<rnk[yroot])par[xroot]=yroot; else if(rnk[xroot]>rnk[yroot])par[yroot] = xroot;
else{
par[xroot]=yroot;
rnk[yroot]++;
}
}

void dfs(int w){
visited[w]=true;
ancestor[w]=w;
for(int u:adj[w]){
if(!visited[u]){
dfs(u);
union_set(w,u);
ancestor[find_set(u)] = w;
}
}
for(int u:queries[w]){
if(visited[u]){
mp[{min(w,u),max(u,w)}]=ancestor[find_set(u)];
}
}
}

int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>q;
for(int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 1; i <= n; i++)
par[i] = i;
for (int i=1;i<=q;i++) {
int u, v;
cin >> u >> v;if (u>v)swap(u,v);ans.pb({u,v});
queries[u].push_back(v);
queries[v].push_back(u);
}
dfs(1);
for (auto u:ans)cout<<mp[u]<<endl;
}

20344 981 2
20345 1043 2
20346 0 0
20347 301 1
20348
DangAC
Lê Minh Đăng
1005 3
20349 2295 9
20350
JackTor_Guy
Phạm Minh Quang, Long An
5813 18
20351 0 0
20352 28968 437
20353 1729 14
20354 7576 38
20355 798 10
20356 101 1
20357 256 1
20358 30 1

<= Youtube

20359 1268 9
20360 0 0
20360 0 0
20362 456 5
20363 0 0
20364 665 7

Người đẹp trai nhất thế giới không ai sánh bằng:)

20365 3457 7
20366 783 3
20367 0 0
20368 492 2
20369 733 1
20370 7408 21
20371 10 1
20372 101 1
20373 0 0
20373 0 0
20375 698 6
20376 0 0
20377 13154 29
20378 101 1

?

20379 727 1
20380 0 0
20381
Tydo_d
Two in one
18721 267
20382 0 0
20383 842 6
20384 1361 7
20385 101 1

idk

20386 0 0
20386 0 0
20386 0 0
20386 0 0
20386 0 0
20391 1237 4
20392 0 0
20392 0 0

rooster

20392 0 0
20395 5306 67
20396 4896 6
20397 11609 84
20398 0 0
20399 101 1
20400 1436 7