#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, M, dfn[100005], dfnn, low[100005], cpn[100005], cpnn, sz[100005], T[100005];
vector<int> edge[100005];
vector<pii> bdge[100005];
ll ans;
void dfs(int x, int p) {
dfn[x] = low[x] = ++dfnn;
N++;
for (auto i : edge[x]) {
if (i == p) continue;
if (dfn[i]) {
if (dfn[i] < dfn[x]) low[x] = min(low[x], dfn[i]);
continue;
}
dfs(i, x);
low[x] = min(low[x], low[i]);
}
}
void bcc(int x, int c) {
cpn[x] = c;
sz[c]++;
for (auto i : edge[x]) {
if (cpn[i]) continue;
if (low[i] == dfn[i]) {
bdge[++cpnn].emplace_back(c, i);
bdge[c].emplace_back(cpnn, x);
bcc(i, cpnn);
}
else bcc(i, c);
}
}
void calc(int x, int p) {
ll n = sz[x], t = (N - n) * (N - n);
ans += n * (n - 1) * (n - 2) + 2 * (n - 1) * (n - 1) * (N - n);
for (auto i : bdge[x]) {
if (i.ff == p) continue;
calc(i.ff, x);
ans -= 2 * (n - 1) * sz[i.ff] * T[i.ss];
T[i.ss] += sz[i.ff];
sz[x] += sz[i.ff];
t -= 1ll * sz[i.ff] * sz[i.ff];
}
ans += n * (t - 1ll * (N - sz[x]) * (N - sz[x]));
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n; cin >> n >> M;
for (int i = 0; i < M; ++i) {
int x, y; cin >> x >> y;
edge[x].push_back(y);
edge[y].push_back(x);
}
for (int i = 1; i <= n; ++i) {
if (dfn[i]) continue;
N = 0;
dfs(i, i);
bcc(i, ++cpnn);
calc(cpnn, cpnn);
}
cout << ans;
return 0;
}
Compilation message
count_triplets.cpp:7:8: error: 'pii' was not declared in this scope
vector<pii> bdge[100005];
^~~
count_triplets.cpp:7:11: error: template argument 1 is invalid
vector<pii> bdge[100005];
^
count_triplets.cpp:7:11: error: template argument 2 is invalid
count_triplets.cpp: In function 'void bcc(int, int)':
count_triplets.cpp:30:17: error: request for member 'emplace_back' in 'bdge[(++ cpnn)]', which is of non-class type 'int'
bdge[++cpnn].emplace_back(c, i);
^~~~~~~~~~~~
count_triplets.cpp:31:12: error: request for member 'emplace_back' in 'bdge[c]', which is of non-class type 'int'
bdge[c].emplace_back(cpnn, x);
^~~~~~~~~~~~
count_triplets.cpp: In function 'void calc(int, int)':
count_triplets.cpp:41:22: error: 'begin' was not declared in this scope
for (auto i : bdge[x]) {
^
count_triplets.cpp:41:22: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:95:0,
from count_triplets.cpp:1:
/usr/include/c++/7/valarray:1211:5: note: 'std::begin'
begin(const valarray<_Tp>& __va)
^~~~~
/usr/include/c++/7/valarray:1211:5: note: 'std::begin'
count_triplets.cpp:41:22: error: 'end' was not declared in this scope
for (auto i : bdge[x]) {
^
count_triplets.cpp:41:22: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:95:0,
from count_triplets.cpp:1:
/usr/include/c++/7/valarray:1231:5: note: 'std::end'
end(const valarray<_Tp>& __va)
^~~
/usr/include/c++/7/valarray:1231:5: note: 'std::end'