Username Points ▴ Problems About
1 0 0
1 0 0

include<bits/stdc++.h>

using namespace std;
vector<int> p,sl, mx;
void init(int n) {
p.resize(n+1);
sl.resize(n+1);
mx.resize(n+1);
for (int i=1; i<=n; i++){
p[i] = i;
sl[i]= 1;
mx[i]=i;
}

}

int find (int a) {
if (a == p[a]) return a;
return p[a]=find(p[a]);
}

void union_set (int a, int b) {
a = find(a);
b = find(b);
if (p[a]>p[b]) {
swap(a,b);
p[a]+= p[b];
p[b] = a;
}
}

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,m;
cin>> n>> m;
init(n);
int tg =n;
while (m--){
int a,b;
cin>> a>> b;
if (union_set(a, b)) {
sl = max(sl, p.size(a));
tg--;
}
cout<< tg << ' ' << sl << '\n';
}
return 0;
}

1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
1
BaAnhHT
Hoàng Bá Anh
0 0
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0

nothing

1 0 0
1 0 0
1 0 0
1 0 0
1 0 0

bhhh

25 40 1
26 45 1
26 45 1
28 101 1
28 101 1
30 197 2
30 197 2
30 197 2
30 200 1
30 201 1
35 225 2
36 269 1
37 288 3
37 301 1
39 401 1
40 541 2
41 621 2
42 943 9
43
hnhlongtm
Trần Minh Long
962 13
44 1132 4
45 1310 7
46 1423 9
47 1447 5
47 1501 1
49 1792 2
50 1849 15
51 1880 13
51 2050 6
53 2161 4
54 2378 5
55
anhuynt
Trịnh Nguyễn An Huy
2575 4
56 2637 2
57 2884 8
58 3500 7

sssss

59 4313 9
60
Syn 1325
4521 8
61
minhtriethansome
Phạm Minh Triết
4627 71
62 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;
}

63 5860 70
64 5929 6
65
nguyenanhdaoht12 1223
nguyenvangiabao
5986 76

tôi tên là nguyễn văn giabao học sinh lớp 3/1.ha

66 6395 14
67
hnhlongvbh
Võ Hoàng Bảo Long
7141 24
68 7201 21
69 7561 40
70 7689 42
71 7812 23
72 8153 38
73 8160 44
74
memeq 1931
Võ Ngọc Sinh
8806 17
75 9702 29
76 9795 13
77 10187 14
78
Critcal
Nguyen Le Chau
12625 79

I, Diamond Sword, will strike you down! Okay just kidding but... Why are you even here? Well, you maybe my classmates but still, what is the point of coming here if you are not a hacker or some ragebaiter who decide to copyright strike the Nyan Cat?
Seriously, I can't be serious, like there can't be a single time where I just don't burst out laughing even at a moment where I don't want to. By the way, I am Critcal and I love Nyan Cat so that explain the words I just said, and to finish it off here is a gif of Nyan Cat and here is some EMOjis: 🙂 🙁 😈 😠 :

79 12648 16
80
yenmai2832008
Vũ Thị Yến Mai
13363 123

hi 🙂

81 13859 67
82
lpa
Yae Miko
14448 48
83 14649 29
84
Ragnakrog 1069
Quá khó để quên em
16052 50
85
quanpham_08092012
Phạm Minh Quân
16320 321

86 16324 21
87
thuongvng 1393
Trần Nguyễn Đan Quỳnh
19584 326
88
nguyenngoccaosang 1442
Nguyễn Ngọc Cao Sang
20061 76

Acc phụ của Sang522008

89
tk22NguyenPhuongLam 1301
Nguyễn Phương Lâm
20490 328

Blockquote

Đây là:enter code hể

summary

summary
  • \[$detail$\]

90
MinhBùi_288
Bùi Minh
22389 119

91
nguyenminhkhoi1234 1291
NguyenMinhKhoi
22894 176

Hello! I'm Nguyen Minh Khoi 🙂

92 23386 74
93 23695 70
94
nguyenthinhuquynh 1227
Nguyễn Thị Như Quỳnh
24422 101

an tê ô

95 24752 164
96
elsu 989
NoNameNoBody
26053 213

Tôi elsu
Bị aaiibbxx phá hoại cuộc sống

97
n2loclm 1233
Lê Minh Lộc
32778 687
98
trvhung 1720
Trần Việt Hưng
33974 178
99 35282 511
100
vongocsinh 1948
Võ Ngọc Sinh
37177 343