#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug { 
    ($($a: expr),*) => { 
        println!(concat!($(stringify!($a)," = {:?}, "),*), $($a),*);
    } 
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

pub struct UnionFindSize {
    parent: Vec<usize>,
    size: Vec<usize>,
}
impl UnionFindSize {
#[allow(dead_code)]
    pub fn new(n: usize) -> Self {
        let mut parent = vec![0; n];
        for i in 0..n {
            parent[i] = i;
        }
        UnionFindSize {
            parent: parent,
            size: vec![1; n],
        }
    }
#[allow(dead_code)]
    pub fn root(&mut self, a: usize) -> usize {
        let par = self.parent[a];
        if par != a {
            self.parent[a] = self.root(par);
        }
        self.parent[a]
    }
#[allow(dead_code)]
    pub fn unite(&mut self, a: usize, b: usize) {
        let a = self.root(a);
        let b = self.root(b);
        if a == b {
            return;
        }
        if self.size[a] > self.size[b] {
            self.parent[b] = a;
            self.size[a] += self.size[b];
        } else {
            self.parent[a] = b;
            self.size[b] += self.size[a];
        }
    }
#[allow(dead_code)]
    pub fn is_same(&mut self, a: usize, b: usize) -> bool {
        self.root(a) == self.root(b)
    }
#[allow(dead_code)]
    pub fn size(&mut self, a: usize) -> usize {
        let par = self.root(a);
        self.size[par]
    }
}

fn solve() {
    let (n, m) = get!(usize, usize);
    let ab = get!(usize, usize; m);

    let mut tree = UnionFindSize::new(n as usize +1);
    let mut res = vec![0; m];
    res[m-1] = n*(n-1)/2;
    for i in (1..m).rev() {
        if tree.is_same(ab[i].0, ab[i].1) {
            res[i-1] = res[i];
        } else {
            res[i-1] = res[i] - tree.size(ab[i].0) * tree.size(ab[i].1);
        }
        tree.unite(ab[i].0, ab[i].1);
    }
    
    for r in res {
        println!("{}", r);
    }
}


Measured memory_bytes: 13692