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
1 0 0

bhhh

1 0 0
27 40 1
28 45 1
28 45 1
30 101 1
30 101 1
32 197 2
32 197 2
32 197 2
32 200 1
32 201 1
37 225 2
38 269 1
39 288 3
39 288 3
41 401 1
42 541 2
43 621 2
44
hnhlongvbh
Võ Hoàng Bảo Long
872 11
45
hnhlongtm
Trần Minh Long
906 12
46 943 9
47 1132 4
48 1203 3
49 1310 7
50 1423 9
51 1447 5
51 1501 1
53 1792 2
54 1849 15
55 1880 13
55 2050 6
57 2161 4
58 2378 5
59 2526 8
60
anhuynt
Trịnh Nguyễn An Huy
2575 4
61 2855 8
62 2884 8
63 3500 7

sssss

64
Syn 1325
4521 8
65 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;
}

66 4848 17
67
Critcal
Nguyen Le Chau
5414 47

This account was made to exercise coding skill ,which my program languages teacher tell me and his other pupils to do. Now it's time to moving to other things.
I know this doesn't talk about my information but that is PRIVATE INFO that i can't tell to YOU, the one who is reading this. I was pretty nervous when i see the problems tab of me are different, but it's just a setting. it took me some time to found it's a setting, pretty fun case, right? Alright, thanks for reading this! BTW, I love Nyan cat!

68
nguyenanhdaoht12 1222
nguyenvangiabao
5854 74

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

69 5860 70
70 5929 6
71 7201 21
72 7545 42
73 7561 40
74
thuongvng 1180
Nguyễn Thị Thương
8000 89
75 8535 43
76
memeq 1931
Võ Ngọc Sinh
8806 17
77 9702 29
78 9795 13
79 10187 14
80 11554 15
81 12648 16
82
yenmai2832008
Vũ Thị Yến Mai
12901 120

hi 🙂

83 13745 25
84 13859 67
85
nguyenminhkhoi1234
NguyenMinhKhoi
14199 94

I'm Nguyen Minh Khoi from Ninh Binh

86
lpa
Yae Miko
14448 48
87
quanpham_08092012
Phạm Minh Quân
15462 294

Dont know
my roblox acc is minh_quaaann
pls play with me

88
Ragnakrog 1069
Quá khó để quên em
16052 50
89
tk22NguyenPhuongLam 1301
Nguyễn Phương Lâm
17729 293
90
nguyenngoccaosang 1442
Nguyễn Ngọc Cao Sang
20061 76

Acc phụ của Sang522008

91 22823 68
92
nguyenthinhuquynh 1198
Nguyễn Thị Như Quỳnh
22995 91

an tê ô

93
elsu 989
NoNameNoBody
25234 209

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

94 25606 164
95
n2loclm 1233
Lê Minh Lộc
32747 660
96
trvhung 1566
Trần Việt Hưng
33968 175
97
huyquang_25 1478
Lê Quang Huy
34984 508
98
vongocsinh 1882
Võ Ngọc Sinh
37239 344
99
Sang522008 1525
Nguyễn Ngọc Cao Sang
37307 873

Nick Phụ: nguyenngoccaosang , NNCS

Newbie


#include <bits/stdc++.h>

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout<<"Cao Sangg";
}

Profile
FaceBook

100
khactrung1912 1725
Nguyễn Khắc Trung
37452 281