#include <iostream>
#include <vector>
using namespace std;
pair<int, int> e[200005];
vector<pair<int, int>> g[100005];
long long int dd[100005], a[100005], b[100005], tin[100005], f[100005], s[100005], z = 0;
vector<int> gg[100005], v;
void dfs(int x, int p) {
tin[x] = f[x] = ++z;
for (auto w : g[x]) {
if (w.first == p) continue;
if (tin[w.first]) {
f[x] = min(f[x], tin[w.first]);
}
else {
dfs(w.first, x);
f[x] = min(f[x], f[w.first]);
if (tin[x] < f[w.first]) {
dd[w.second] = 1;
}
}
}
}
void dfs2(int x, int h) {
b[x] = h;
a[h]++;
for (auto w : g[x]) {
if (b[w.first] || dd[w.second]) continue;
dfs2(w.first, h);
}
}
long long int res = 0, d = 0;
void dfs3(int x, int p) {
v.push_back(x);
s[x] = a[x];
d += a[x];
tin[x] = 1;
for (int w : gg[x]) {
if (w == p) continue;
dfs3(w, x);
s[x] += s[w];
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
e[i] = {u, v};
g[u].push_back({v, i});
g[v].push_back({u, i});
}
for (int i = 1; i <= n; i++) {
if (tin[i] == 0) {
dfs(i, -1);
}
}
z = 0;
for (int i = 1; i <= n; i++) {
if (b[i] == 0) {
z++;
dfs2(i, z);
}
}
for (int i = 1; i <= m; i++) {
if (dd[i] == 1) {
gg[b[e[i].first]].push_back(b[e[i].second]);
gg[b[e[i].second]].push_back(b[e[i].first]);
}
}
for (int i = 1; i <= n; i++) tin[i] = 0;
for (int i = 1; i <= n; i++) {
if (tin[i] == 0) {
v.clear();
d = 0;
dfs3(i, -1);
for (int w : v) {
res += (a[w] - 1) * a[w] * a[w] / 2;
res += d - a[w];
res += (a[w] - 1) * a[w] * (d - a[w]);
res += (s[w] - a[w]) * (d - s[w]);
}
}
}
cout << (res - n * (n - 1)) * 2;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
46 ms |
22172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
10932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
19660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
10832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
62 ms |
19704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |