#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define ll long long
using namespace std;
bool visited[100000];
ll n, m, k, a, b, g, cnt, f, rt, apcnt, low[100000], st[100000], sz[200000], dp[200000];
vector <ll> G, blocks;
bool ap[100000];
vector <ll> V, adj[100000], X[100000], E[200000];
void tar(ll u, ll p) {
G.push_back(u);
st[u] = low[u] = ++cnt;
V.push_back(u);
ll rch = 0;
for (auto v : adj[u]) {
if (!st[v]) {
++rch;
tar(v, u);
low[u] = min(low[u], low[v]);
if (p != -1 && low[v] >= st[u]) ap[u] = 1;
if (low[v] >= st[u]) {
blocks.push_back(k);
while (!V.empty()) {
auto x = V.back();
V.pop_back();
X[x].push_back(k);
++sz[k];
if (x == v) break;
}
X[u].push_back(k);
++sz[k];
++k;
}
}
else if (v != p) {
low[u] = min(low[u], st[v]);
}
}
if (p == -1 && rch > 1) ap[u] = 1;
}
void calc(ll u, ll p) {
//cout << u << '\n';
if (u >= n) dp[u] = sz[u] - E[u].size();
else dp[u] = 1;
//cout << u << " " << dp[u] << '\n';
for (auto v : E[u]) {
if (v != p) {
calc(v, u);
dp[u] += dp[v];
if (u >= n) {
//cout << (sz[u]-E[u].size()) << " " << (dp[v] - 1) << " " << sz[u] << '\n';
//cout << u << '\n';
f += (sz[u] - E[u].size()) * (sz[u] - 2) * (dp[v] - 1) * 2;
f += (sz[u] - E[u].size()) * (G.size() - sz[u] - dp[v] + 1) * (dp[v]-1) * 2;
}
}
}
for (auto v : E[u]) {
if (v != p) {
if (u >= n) {
//cout << (dp[v]-1) << " " << (G.size() - dp[v]) << '\n';
f += (dp[v]-1) * (G.size() - dp[v]);
f += (E[u].size() - 1) * (G.size() - dp[v] - 1);
}
}
}
if (u < n) {
f += (G.size() - dp[u]) * (dp[u] - 1);
}
else {
//cout << u << " " << dp[u] << '\n';
f += (sz[u] - E[u].size()) * (sz[u] - 2) * (G.size() - dp[u] - (p != -1)) * 2;
if (G.size() >= 2) f += (sz[u] - E[u].size()) * E[u].size() * (G.size() - 2);
}
}
int main() {
cin >> n >> m;
for (int i=0; i<m; ++i) {
cin >> a >> b;
--a, --b;
adj[a].push_back(b);
adj[b].push_back(a);
}
k = n;
for (int i=0; i<n; ++i) {
if (!st[i]) {
G.clear();
blocks.clear();
V.clear();
tar(i, -1);
for (auto u : G) {
if (ap[u]) {
for (auto v : X[u]) {
E[u].push_back(v);
E[v].push_back(u);
}
}
}
for (auto u : blocks) {
if (sz[u] >= 3) {
f += (sz[u] - E[u].size()) * (sz[u]-1) * (sz[u]-2);
//f += E[u].size() * (sz[u]-1) * (sz[u]-2);
}
}
if (!blocks.empty()) calc(blocks[0], -1);
}
}
cout << f << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
3 ms |
12888 KB |
Output is correct |
4 |
Correct |
3 ms |
12888 KB |
Output is correct |
5 |
Correct |
3 ms |
12892 KB |
Output is correct |
6 |
Correct |
3 ms |
12892 KB |
Output is correct |
7 |
Incorrect |
3 ms |
12892 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
3 ms |
12888 KB |
Output is correct |
4 |
Correct |
3 ms |
12888 KB |
Output is correct |
5 |
Correct |
3 ms |
12892 KB |
Output is correct |
6 |
Correct |
3 ms |
12892 KB |
Output is correct |
7 |
Incorrect |
3 ms |
12892 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
30656 KB |
Output is correct |
2 |
Correct |
86 ms |
30728 KB |
Output is correct |
3 |
Incorrect |
93 ms |
35044 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
12888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
99 ms |
29652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
12892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
117 ms |
29840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
3 ms |
12888 KB |
Output is correct |
4 |
Correct |
3 ms |
12888 KB |
Output is correct |
5 |
Correct |
3 ms |
12892 KB |
Output is correct |
6 |
Correct |
3 ms |
12892 KB |
Output is correct |
7 |
Incorrect |
3 ms |
12892 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
3 ms |
12888 KB |
Output is correct |
4 |
Correct |
3 ms |
12888 KB |
Output is correct |
5 |
Correct |
3 ms |
12892 KB |
Output is correct |
6 |
Correct |
3 ms |
12892 KB |
Output is correct |
7 |
Incorrect |
3 ms |
12892 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |