This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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();
ll cnte = 0;
for (int x : inc)
cnte += adj[x].size();
cnte /= 2;
if (cnte == K - 1)
total += (K * (K - 1) * (K - 2)) / 3;
else
total += (K * (K - 1) * (K - 2));
}
}
// cout<<"ANSWER: ";
cout<<total<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |