Submission #52631323


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.first << ' ' << p.second << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define fi first
#define se second

const long double PI = acos(-1);

ll n, m;
bool vis[200005];
vector<int> v[200005];

ll dfs(int x) {
	vis[x] = true;
	ll all = 1;
	for (auto i : v[x]) {
		if (vis[i]) continue;
		all += dfs(i);
	}
	return all;
}

int main()
{
   ios::sync_with_stdio(false);

   cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}

	ll total = -m;
	for (int i = 0; i < n; i++) {
		if (!vis[i]) {
			ll sz = dfs(i);
			total += sz * (sz - 1) / 2;
		}
	}

	cout << total;

   return 0;
}

Submission Info

Submission Time
Task D - New Friends
User lungualex00
Language C++ 20 (gcc 12.2)
Score 350
Code Size 1720 Byte
Status AC
Exec Time 57 ms
Memory 19820 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 36
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 53 ms 15164 KiB
random_02.txt AC 45 ms 10748 KiB
random_03.txt AC 34 ms 12976 KiB
random_04.txt AC 34 ms 11932 KiB
random_05.txt AC 53 ms 15248 KiB
random_06.txt AC 45 ms 11860 KiB
random_07.txt AC 24 ms 12040 KiB
random_08.txt AC 16 ms 10072 KiB
random_09.txt AC 17 ms 5968 KiB
random_10.txt AC 12 ms 4444 KiB
random_11.txt AC 7 ms 4204 KiB
random_12.txt AC 2 ms 3520 KiB
random_13.txt AC 17 ms 5976 KiB
random_14.txt AC 8 ms 4180 KiB
random_15.txt AC 3 ms 3784 KiB
random_16.txt AC 6 ms 4268 KiB
random_17.txt AC 18 ms 6160 KiB
random_18.txt AC 2 ms 3608 KiB
random_19.txt AC 45 ms 14296 KiB
random_20.txt AC 15 ms 7392 KiB
random_21.txt AC 43 ms 14236 KiB
random_22.txt AC 28 ms 10712 KiB
random_23.txt AC 35 ms 15060 KiB
random_24.txt AC 35 ms 15040 KiB
random_25.txt AC 57 ms 19048 KiB
random_26.txt AC 18 ms 8912 KiB
random_27.txt AC 35 ms 19820 KiB
random_28.txt AC 2 ms 3668 KiB
random_29.txt AC 2 ms 3616 KiB
random_30.txt AC 1 ms 3564 KiB
random_31.txt AC 1 ms 3432 KiB
random_32.txt AC 1 ms 3616 KiB
random_33.txt AC 1 ms 3408 KiB
sample_01.txt AC 1 ms 3428 KiB
sample_02.txt AC 1 ms 3480 KiB
sample_03.txt AC 1 ms 3484 KiB