This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
using namespace std;
const int N = 1e5 + 5;
vector<int> g[N], g2[N], v;
int tin[N], mnt[N], sz[N];
bool used[N];
int timer = 0, cnt = 0, cv = 0;
int n, m;
ll ans = 0;
void dfs(int node, int anc) {
mnt[node] = tin[node] = ++timer;
used[node] = 1;
cnt++;
v.push_back(node);
for (int to : g[node]) {
if (to != anc) {
if (!used[to]) {
dfs(to, node);
mnt[node] = min(mnt[node], mnt[to]);
if (mnt[to] >= tin[node]) {
g2[node].push_back(cv);
while (v.back() != node) {
g2[cv].push_back(v.back());
v.pop_back();
}
cv++;
}
}
else {
mnt[node] = min(mnt[node], tin[to]);
}
}
}
}
void dive(int node) {
sz[node] = (node < n);
for (int to : g2[node]) {
dive(to);
sz[node] += sz[to];
if (node >= n)
ans -= sz[to] * (ll)(sz[to] - 1) * (ll)g2[node].size();
}
if (node >= n) {
ans -= (cnt - sz[node]) * (ll)(cnt - sz[node] - 1) * (ll)g2[node].size();
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].push_back(b);
g[b].push_back(a);
}
cv = n;
for (int i = 0; i < n; i++) {
if (!used[i]) {
cnt = 0;
dfs(i, -1);
ans += cnt * (ll)(cnt - 1) * (cnt - 2);
dive(i);
}
}
cout << ans;
return 0;
}
# | 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... |