提出 #52598181


ソースコード 拡げる

#include <bits/stdc++.h>

using namespace std;
#define int long long
typedef long double ld;
typedef pair<int, int> pii;
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define inf 1e15+5
const int mod = 1e9+7;

string printBinary(int n){
	int bits = 0;
	int temp = n;
	string result;
	while(temp != 0){
		bits++;
		temp >>= 1;
	}
	for(int i = bits - 1; i >= 0; i--){
		int k = n >> i;
		if(k&1){
			result += '1';
		}
		else result += '0';;
	}
	return result;
}

int mostSF(int n){
	int k = __builtin_clz(n);
	return (32 - k);
}

int fact(int n){
	int ans = 1;
	for(int i = 1; i <= n; i++) ans *= i;
	return ans;
}

int ncr(int n, int r){
	return fact(n) / fact(r) * fact(n-r);
}

bool is_sorted(vector<int>& a){
	int n = a.size();
	for(int i = 0; i + 1 < n; i++){
		if(a[i] > a[i+1]) return 0;
	}
	return 1;
}

int md(int n){
	if(n < 0){
		return ((n % mod) + mod) % mod;
	}
	return n % mod;
}

const int N = 2e5+10;
vector<int> graph[N];
bool visited[N];
int counter = 0, nn = 0;
int answer = 0;

void dfs(int v){
	visited[v] = 1;
	nn++;
	counter += graph[v].size();
	for(auto c: graph[v]){
		if(!visited[c]){
			dfs(c);
		}
	}
}

signed main(){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		graph[x].pb(y);
		graph[y].pb(x);
	}
	for(int i = 1; i <= n; i++){
		if(!visited[i]){
			counter = 0;
			nn = 0;
			dfs(i);
			int should = nn * (nn - 1) / 2;
			answer += (should - counter / 2);
		}
	}
	cout << answer << endl;
}

提出情報

提出日時
問題 D - New Friends
ユーザ Wasif_Shahzad
言語 C++ 20 (gcc 12.2)
得点 350
コード長 1593 Byte
結果 AC
実行時間 148 ms
メモリ 20844 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 350 / 350
結果
AC × 3
AC × 36
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
random_01.txt AC 140 ms 16908 KiB
random_02.txt AC 113 ms 13264 KiB
random_03.txt AC 87 ms 13488 KiB
random_04.txt AC 87 ms 12732 KiB
random_05.txt AC 129 ms 16960 KiB
random_06.txt AC 110 ms 14240 KiB
random_07.txt AC 57 ms 12032 KiB
random_08.txt AC 36 ms 10204 KiB
random_09.txt AC 44 ms 8752 KiB
random_10.txt AC 29 ms 5828 KiB
random_11.txt AC 17 ms 4888 KiB
random_12.txt AC 3 ms 3740 KiB
random_13.txt AC 45 ms 8576 KiB
random_14.txt AC 19 ms 5020 KiB
random_15.txt AC 6 ms 3824 KiB
random_16.txt AC 14 ms 4636 KiB
random_17.txt AC 49 ms 8616 KiB
random_18.txt AC 3 ms 3632 KiB
random_19.txt AC 114 ms 14448 KiB
random_20.txt AC 33 ms 7348 KiB
random_21.txt AC 111 ms 14536 KiB
random_22.txt AC 73 ms 10744 KiB
random_23.txt AC 96 ms 15816 KiB
random_24.txt AC 102 ms 15840 KiB
random_25.txt AC 148 ms 20088 KiB
random_26.txt AC 39 ms 9280 KiB
random_27.txt AC 86 ms 20844 KiB
random_28.txt AC 3 ms 3688 KiB
random_29.txt AC 2 ms 3676 KiB
random_30.txt AC 2 ms 3480 KiB
random_31.txt AC 2 ms 3440 KiB
random_32.txt AC 2 ms 3528 KiB
random_33.txt AC 2 ms 3400 KiB
sample_01.txt AC 2 ms 3468 KiB
sample_02.txt AC 2 ms 3432 KiB
sample_03.txt AC 2 ms 3404 KiB