Language: C

//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

use std::io::Write;

fn root(p: &Vec<i32>, mut x: usize) -> usize {
    while p[x] >= 0 {
        x = p[x] as usize;
    }
    x
}

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        n: usize,
        m: usize,
        e: [(usize1, usize1, u64); m],
        q: usize,
        p: [(usize1, usize1); q],
    }
    let mut e = e;
    e.sort_by(|a, b| a.2.cmp(&b.2));
    let mut parent = vec![-1; n];
    let mut cost = vec![1000000000 + 1; n];
    let mut sum = 0;
    for (a, b, c) in e {
        let mut a = root(&parent, a);
        let mut b = root(&parent, b);
        if a == b {
            continue;
        }
        sum += c;
        if parent[a] > parent[b] {
            std::mem::swap(&mut a, &mut b);
        }
        parent[a] += parent[b];
        parent[b] = a as i32;
        cost[b] = c;
    }
    for (mut s, mut t) in p {
        let mut ans = 0;
        while s != t {
            if cost[s] < cost[t] {
                ans = cost[s];
                s = parent[s] as usize;
            } else {
                ans = cost[t];
                t = parent[t] as usize;
            }
        }
        writeln!(out, "{}", sum - ans).unwrap();
    }
}

fn main() {
    run();
}


Compiler output:
main.c:2:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '!' token
    2 | macro_rules! input {
      |            ^
main.c:19:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '!' token
   19 | macro_rules! input_inner {
      |            ^
main.c:28:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '!' token
   28 | macro_rules! read_value {
      |            ^
main.c:33:10: error: too many decimal points in number
   33 |         (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
      |          ^~~~~~~
main.c:48:1: error: unknown type name 'use'
   48 | use std::io::Write;
      | ^~~
main.c:48:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before '::' token
   48 | use std::io::Write;
      |        ^~
main.c:50:1: error: unknown type name 'fn'
   50 | fn root(p: &Vec<i32>, mut x: usize) -> usize {
      | ^~
main.c:50:10: error: expected ')' before ':' token
   50 | fn root(p: &Vec<i32>, mut x: usize) -> usize {
      |          ^
      |          )
main.c:57:1: error: unknown type name 'fn'
   57 | fn run() {
      | ^~
main.c: In function 'run':
main.c:58:5: error: unknown type name 'let'
   58 |     let out = std::io::stdout();
      |     ^~~
main.c:58:15: error: 'std' undeclared (first use in this function)
   58 |     let out = std::io::stdout();
      |               ^~~
main.c:58:15: note: each undeclared identifier is reported only once for each function it appears in
main.c:58:18: error: expected ',' or ';' before '::' token
   58 |     let out = std::io::stdout();
      |                  ^~
main.c:59:5: error: unknown type name 'let'
   59 |     let mut out = std::io::BufWriter::new(out.lock());
      |     ^~~
main.c:59:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'out'
   59 |     let mut out = std::io::BufWriter::new(out.lock());
      |             ^~~
main.c:60:5: error: 'input' undeclared (first use in this function); did you mean 'int'?
   60 |     input! {
      |     ^~~~~
      |     int
main.c:60:10: error: expected ';' before '!' token
   60 |     input! {
      |          ^
      |          ;
main.c:68:5: error: 'e' undeclared (first use in this function)
   68 |     e.sort_by(|a, b| a.2.cmp(&b.2));
      |     ^
main.c:68:15: error: expected expression before '|' token
   68 |     e.sort_by(|a, b| a.2.cmp(&b.2));
      |               ^
main.c:68:23: error: too many decimal points in number
   68 |     e.sort_by(|a, b| a.2.cmp(&b.2));
      |                       ^~~~~~
main.c:69:5: error: unknown type name 'let'
   69 |     let mut parent = vec![-1; n];
      |     ^~~
main.c:69:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'parent'
   69 |     let mut parent = vec![-1; n];
      |             ^~~~~~
main.c:69:31: error: 'n' undeclared (first use in this function)
   69 |     let mut parent = vec![-1; n];
      |                               ^
main.c:69:32: error: expected ';' before ']' token
   69 |     let mut parent = vec![-1; n];
      |                                ^
      |                                ;
main.c:69:32: error: expected statement before ']' token
main.c:70:5: error: unknown type name 'let'
   70 |     let mut cost = vec![1000000000 + 1; n];
      |     ^~~
main.c:70:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'cost'
   70 |     let mut cost = vec![1000000000 + 1; n];
      |             ^~~~
main.c:70:42: error: expected ';' before ']' token
   70 |     let mut cost = vec![1000000000 + 1; n];
      |                                          ^
      |                                          ;
main.c:70:42: error: expected statement before ']' token
main.c:71:5: error: unknown type name 'let'
   71 |     let mut sum = 0;
      |     ^~~
main.c:71:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sum'
   71 |     let mut sum = 0;
      |             ^~~
main.c:72:10: error: 'a' undeclared (first use in this function)
   72 |     for (a, b, c) in e {
      |          ^
main.c:72:13: error: 'b' undeclared (first use in this function)
   72 |     for (a, b, c) in e {
      |             ^
main.c:72:16: error: 'c' undeclared (first use in this function)
   72 |     for (a, b, c) in e {
      |                ^
main.c:72:17: error: expected ';' before ')' token
   72 |     for (a, b, c) in e {
      |                 ^
      |                 ;
main.c:72:17: error: expected expression before ')' token
main.c:72:19: error: 'in' undeclared (first use in this function); did you mean 'int'?
   72 |     for (a, b, c) in e {
      |                   ^~
      |                   int
main.c:72:21: error: expected ';' before 'e'
   72 |     for (a, b, c) in e {
      |                     ^~
      |                     ;
main.c: At top level:
main.c:101:1: error: unknown type name 'fn'
  101 | fn main() {
      | ^~