#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define pb push_back
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define rep(i,a,b) for(int i=a;i<b;i++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T, typename T1>T amax(T &a, T1 b) {if (b > a)a = b; return a;}
template<typename T, typename T1>T amin(T &a, T1 b) {if (b < a)a = b; return a;}
template<typename T>
using pbds = tree<T , null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;
const int N = 1e5 + 5;
int mxSize;
int parent[N], siz[N];
int findParent(int i)
{
if (i == parent[i])
return i;
return parent[i] = findParent(parent[i]);
}
void unionNodes(int a, int b)
{
int parent_a = findParent(a), parent_b = findParent(b);
if (parent_a == parent_b)
return;
if (siz[parent_a] >= siz[parent_b]) {
swap(parent_a, parent_b);
}
siz[parent_b] += siz[parent_a];
parent[parent_a] = parent_b;
return;
}
void cleardsu(int n) {
mxSize = 0;
for (int i = 0; i <= n; i++) {
parent[i] = i;
siz[i] = 1;
}
}
void solve() {
int n, d; cin >> n >> d;
cleardsu(n);
int not_connected = 1;
int disjoint_sets = n;
// we need a data structure to store the sorted sizes of disjoint sets
// compute the suffix sum effectively
multiset<int, greater<int>>st;
for (int i = 1; i <= n; i++) {
st.insert(1);
}
for (int i = 0; i < d; i++) {
int a, b; cin >> a >> b;
int xx = findParent(a);
int yy = findParent(b);
if (xx == yy) {
// if there exist some relation not still connected we can connect them
not_connected++;
}
else {
// remove two sizes and add one size
st.erase(st.find(siz[xx]));
st.erase(st.find(siz[yy]));
st.insert(siz[xx] + siz[yy]);
unionNodes(a, b);
disjoint_sets--;
}
int x = findParent(a);
// find the sum of top not_connected elements
int cnt = 0;
int sum = 0;
for (auto x : st) {
sum += x;
cnt++;
if (cnt == not_connected) {
break;
}
}
amax(mxSize, siz[x]);
// out of these not connected how many we can fulfill
// find out the number of disjoint sets in dsu
// connect top not connected sets
cout << sum - 1 << endl;
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#ifdef SIEVE
sieve();
#endif
#ifdef NCR
init();
#endif
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
620A - Professor GukiZ's Robot | 1342A - Road To Zero |
1520A - Do Not Be Distracted | 352A - Jeff and Digits |
1327A - Sum of Odd Integers | 1276A - As Simple as One and Two |
812C - Sagheer and Nubian Market | 272A - Dima and Friends |
1352C - K-th Not Divisible by n | 545C - Woodcutters |
1528B - Kavi on Pairing Duty | 339B - Xenia and Ringroad |
189A - Cut Ribbon | 1182A - Filling Shapes |
82A - Double Cola | 45A - Codecraft III |
1242A - Tile Painting | 1663E - Are You Safe |
1663D - Is it rated - 3 | 1311A - Add Odd or Subtract Even |
977F - Consecutive Subsequence | 939A - Love Triangle |
755A - PolandBall and Hypothesis | 760B - Frodo and pillows |
1006A - Adjacent Replacements | 1195C - Basketball Exercise |
1206A - Choose Two Numbers | 1438B - Valerii Against Everyone |
822A - I'm bored with life | 9A - Die Roll |