#include <bits/stdc++.h>
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 100005
#define M ll(998244353)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef short int si;
vector <int> g[N];
bool mk[N], mkr[N];
int ans, i, j, n, m;
ll anser, siz[N];
void calc(int v, int p)
{
if (p != -1) {siz[p] -= siz[v]; siz[v] += siz[p];}
for (auto it : g[v]) anser += (siz[v] - 1 - siz[it]) * siz[it];
for (auto it : g[v]) {if (p == it) continue; calc(it, v);}
if (p != -1) {siz[v] -= siz[p]; siz[p] += siz[v];}
}
void dfs(int v, int p)
{
siz[v] = 0;
for (auto it : g[v])
{
if (it == p) continue;
dfs(it, v);
siz[v] += siz[it];
}
siz[v]++;
if (i == v) calc(v, -1);
}
bool dostig(int v, int to)
{
if (mk[v]) return 0;
if (v == to) return 1;
mk[v] = 1;
bool f = 0;
for (auto it : g[v]) f |= dostig(it, to);
mk[v] = 0;
if (f && v != i && !mkr[v]) {mkr[v] = 1; ans++;}
return f;
}
bool opr(int v, int p)
{
mkr[v] = 1;
for (auto it : g[v])
{
if (it == p) continue;
if (mkr[it]) return 1;
if (opr(it, v)) return 1;
}
return 0;
}
int main()
{
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
if (m <= n - 1 && n > 10)
{
for (i = 1; i <= n; i++) if (siz[i] == 0) dfs(i, -1);
cout << anser << endl;
exit(0);
}
if (n <= 10 && m <= 100)
{
ans = 0;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
if (i != j){for (int u = 0; u < 51; u++) mkr[u] = 0; dostig(i, j);}
cout << ans << endl;
}
else
{
for (int i = 1; i <= n; i++)
{
if (mkr[i]) continue;
kol = 0;
if (opr(i, -1)) anser += max(0ll, kol * (kol - 1) * (kol - 2)); else if (kol > 2) dfs(i, -1);
}
}
}
Compilation message
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:133:13: error: 'kol' was not declared in this scope
kol = 0;
^~~