Submission #1070955

# Submission time Handle Problem Language Result Execution time Memory
1070955 2024-08-22T21:48:08 Z pawned Duathlon (APIO18_duathlon) C++17
0 / 100
37 ms 10440 KB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

const char nl = '\n';

void fastIO() {
	ios::sync_with_stdio(false);
	cin.tie(0);
}

const int MAX = 1e5 + 5;

int N, M;

bool vis[MAX];
vi adj[MAX];

vi inc;

void dfs(int n) {
	vis[n] = true;
	inc.pb(n);
	for (int x : adj[n]) {
		if (!vis[x])
			dfs(x);
	}
}

int main() {
	fastIO();
	cin>>N>>M;
	for (int i = 0; i < M; i++) {
		int u, v;
		cin>>u>>v;
		u--; v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	ll total = 0;
	for (int i = 0; i < N; i++) {
		if (!vis[i]) {
			inc.clear();
			dfs(i);
			int K = inc.size();
			total += (K * (K - 1) * (K - 2)) / 6;
		}
	}
//	cout<<"ANSWER: ";
	cout<<total * 2<<endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 10440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 7896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 7984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -