#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[derive(Debug)]
struct UnionFind {
    parents: Vec<usize>,
    size: Vec<usize>,
}
impl UnionFind {
    fn init(n: usize) -> UnionFind {
        let parents: Vec<usize> = (0..n).into_iter().collect();
        let size = vec![1; n];
        UnionFind {
            parents: parents,
            size: size,
        }
    }
    fn find(&mut self, x: usize) -> usize {
        if self.parents[x] == x {
            x
        } else {
            let val = self.parents[x];
            self.parents[x] = self.find(val);
            self.parents[x]
        }
    }
    fn unite(&mut self, mut x: usize, mut y: usize) {
        x = self.find(x);
        y = self.find(y);
        if x == y {
            return;
        }
        if self.size[x] < self.size[y] {
            self.parents[x] = y;
            self.size[y] += self.size[x];
        } else {
            self.parents[y] = x;
            self.size[x] += self.size[y];
        }
    }
    fn get_size(&mut self, x: usize) -> usize {
        let x_root = self.find(x); 
        self.size[x_root]
    }
    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
}

fn main() {
    input! {
        n: usize,
        m: usize,
        abs: [(usize1, usize1); m],
    }
    let mut union_find = UnionFind::init(n);
    let mut ans_vec: Vec<usize> = Vec::new();
    let mut ans = n * (n - 1) / 2;
    ans_vec.push(ans);

    for (a, b) in abs.into_iter().rev() {
        if !union_find.same(a, b) {
            let val = union_find.get_size(a) * union_find.get_size(b);
            ans -= val;
            union_find.unite(a, b);
        }
        ans_vec.push(ans);
    }
    ans_vec.pop();
    for ans in ans_vec.into_iter().rev() {
        println!("{}", ans);
    }
}


Measured memory_bytes: 10864