C - Make it Simple
Source: atcoder
Difficulty: 300

Problem Statement
You are given an undirected graph with
N
vertices and
M
edges, where the vertices are numbered
1
through
N
and the edges are numbered
1
through
M
. Edge
i
connects vertices
u_i
and
v_i
.
To make the graph simple by removing edges, what is the minimum number of edges that must be removed?
Here, a graph is called simple if and only if it does not contain self-loops or multi-edges.
Constraints
1 \leq N \leq 2 \times 10^5
0 \leq M \leq 5 \times 10^5
1 \leq u_i \leq N
1 \leq v_i \leq N
All input values are integers.
Input
The input is given from Standard Input in the following format:
N
M
u_1
v_1
u_2
v_2
\vdots
u_M
v_M
Output
Print the minimum number of edges that must be removed to make the graph simple.
Sample Input 1
3 5
1 2
2 3
3 2
3 1
1 1
Sample Output 1
2
By removing edges
3
and
5
, the graph becomes simple. This is one of the ways to remove the minimum number of edges, so the answer is
2
.
Sample Input 2
1 0
Sample Output 2
0
Sample Input 3
6 10
6 2
4 1
5 1
6 6
5 3
5 1
1 4
6 4
4 2
5 6
Sample Output 3
3

C++ solution:
#pragma GCC optimize("O3")
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define IOS ios::sync_with_stdio(false); cin.tie(0)
#define ll long long
#define ld long double
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define fi first
#define se second
 
 
const int N = 2e5 + 10;
const ll LINF = 1e18;
const int INF = 1e9;
const ld PI = 4*atan((ld)1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
 
int main() {
    int n, m;
    cin >> n >> m;
    vector<pii> e;
    for (int i = 0; i < m; ++i) {
        int v, u;
        cin >> v >> u;
        if (v > u) swap(v, u);
        if (v != u) {
            e.push_back({v, u});
        }
    }
    sort(e.begin(), e.end());
    e.erase(unique(e.begin(), e.end()), e.end());
    cout << m - e.size() << '\n';
}

Go solution:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

const (
	inf = 1 << 60
	MOD = 998244353
)

func main() {
	/*** INIT ***/
	defer wt.Flush()
	sc.Buffer([]byte{}, inf)
	sc.Split(bufio.ScanWords)

	_, m := InputInt(), InputInt()
	seen := make(map[int]bool)
	ans := 0
	for i := 0; i < m; i++ {
		u, v := InputInt(), InputInt()
		if v < u {
			u, v = v, u
		}
		if u == v || seen[u<<30+v] == true {
			ans++
		}
		seen[u<<30+v] = true
	}

	OutInt(ans)
}

/*** I/O ***/
func InputInt() int {
	sc.Scan()
	val, _ := strconv.Atoi(sc.Text())
	return val
}

func InputString() string {
	sc.Scan()
	return sc.Text()
}

func OutInt(val int) {
	fmt.Fprintln(wt, val)
}

func OutString(s string) {
	fmt.Fprintln(wt, s)
}

Java solution:
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        StringTokenizer st = new StringTokenizer(br.readLine()," ");
        
        int V = Integer.parseInt(st.nextToken());
        int E = Integer.parseInt(st.nextToken());
        
        List<Integer>[] list = new ArrayList[V+1];
        
        for (int i = 0; i <= V; i++) {
			list[i] = new ArrayList<>();
		}
        
        int cnt = 0;
        for (int i = 0; i < E; i++) {
			st = new StringTokenizer(br.readLine()," ");
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			
			
			if(!list[a].contains(b) && a!=b) {
				list[a].add(b);
				list[b].add(a);
			}
			else {
				cnt++;
			}
		}
        
        System.out.println(cnt);
    }
    
}

JavaScript solution:
"use strict";

class Scanner {
    constructor() {
        this.Separator = ' ';
        this._readAllLines();
    }

    _readAllLines() {
        const fs = require('fs');
        const input = fs.readFileSync('/dev/stdin', 'utf8');
        this._lines = input.split('\n');
        this._lineIndex = 0;
        this._readLine();
    }

    _readLine() {
        this._line = this._lines[this._lineIndex].split(this.Separator);
        this._lineLength = this._line.length;
        this._cursorIndex = 0;
    }

    _next() {
        if (this._cursorIndex >= this._lineLength) {
            this._lineIndex++;
            this._readLine();
        }
        const next = this._line[this._cursorIndex];
        this._cursorIndex++;
        return next;
    }

    nextString() {
        return this._next();
    }

    nextInt() {
        return parseInt(this._next(), 10);
    }

    nextLong() {
        return BigInt(this._next());
    }

    nextDouble() {
        return parseFloat(this._next());
    }

    nextDecimal() {
        return parseFloat(this._next());
    }

    nextChar() {
        return this._next().charAt(0);
    }

    nextCharArray() {
        return this._next().split('');
    }

    array() {
        if (this._cursorIndex >= this._lineLength) {
            this._lineIndex++;
            this._readLine();
        }
        this._cursorIndex = this._lineLength;
        return this._line;
    }

    intArray() {
        return this.array().map(Number);
    }

    longArray() {
        return this.array().map(BigInt);
    }

    doubleArray() {
        return this.array().map(Number);
    }

    decimalArray() {
        return this.array().map(Number);
    }
}

function main() {
    const sc = new Scanner();

    const n = sc.nextInt();
    const m = sc.nextInt();

    let answer = 0;

    const nums = [];
    for (let i = 0; i <= n; i++) {
        nums.push([]);
    }

    for (let i = 0; i < m; i++) {
        const v = sc.nextInt();
        const u = sc.nextInt();

        if (v === u) {
            answer++;
            continue;
        }

        if (nums[v].includes(u)) {
            answer++;
            continue;
        }

        nums[v].push(u);
        nums[u].push(v);
    }

    console.log(answer);
}

main();

Python solution:
import math
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

n, m = MI()
ans = 0

d = {}

for i in range(m):
    u, v = MI()
    if u == v:
        ans += 1
    elif (u, v) in d or (v, u) in d:
        ans += 1
    else:
        d[(u, v)] = 1

print(ans)

Ruby solution:
(N, M), *UV = readlines.map{_1.split.map(&:to_i)}

puts M - UV.map{|u, v| u < v ? [u, v] : u == v ? nil : [v, u]}.compact.uniq.size