#include <bits/stdc++.h>
#define lli long long int
#define ld long double
#define pb push_back
#define MP make_pair
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const int N = 1e5 + 5;
const int INF = 1e9 + 500;
int n, m;
vector<vector<array<int, 2> > > adj(N, vector<array<int, 2> >());
int tim = 0;
vector<int> tin(N, -1), low(N, 0);
vector<array<int, 2> > edg(N);
vector<bool> isBr(N, 0);
vector<int> comp(N, -1), cmpsz(N, 0);
vector<vector<int> > cadj(N, vector<int>());
vector<int> subsz(N, 0);
lli ans = 0;
void find_bridge(int node, int par) {
tin[node] = low[node] = tim++;
for(auto c : adj[node]) {
if(c[0] == par) {
continue;
}
if(tin[c[0]] != -1) {
low[node] = min(low[node], tin[c[0]]);
}
else {
find_bridge(c[0], node);
low[node] = min(low[node], low[c[0]]);
if(low[c[0]] > tin[node]) {
//bridge
isBr[c[1]] = 1;
}
}
}
}
void get_comp(int node, int par, int cm) {
comp[node] = cm;
cmpsz[cm]++;
for(auto c : adj[node]) {
if(c[0] == par || isBr[c[1]]) continue;
get_comp(c[0], node, cm);
}
}
void prec(int node, int par) {
subsz[node] = cmpsz[node];
for(auto c : cadj[node]) {
if(c == par) continue;
prec(c, node);
subsz[node] += subsz[c];
}
}
void dfs(int node, int par) {
lli ret = 0;
lli x = n - cmpsz[node];
for(auto c : cadj[node]) {
if(c == par) {
int sbt = n - subsz[node];
ret += 1ll * cmpsz[node] * sbt * (x - sbt);
continue;
}
int sbt = subsz[c];
ret += 1ll * cmpsz[node] * sbt * (x - sbt);
dfs(c, node);
}
ans += ret;
}
void solve() {
cin >> n >> m;
REP(i, m) {
int u, v;
cin >> u >> v;
edg[i] = {u, v};
adj[u].pb({v, i});
adj[v].pb({u, i});
}
find_bridge(1, 0);
int cur = 1;
for(int i = 1; i <= n; i++) {
if(comp[i] == -1) {
get_comp(i, 0, cur++);
}
// cout << "i:" << i << " comp:" << comp[i] << "\n";
}
for(int i = 0; i < m; i++) {
if(isBr[i]) {
// cout << edg[i][0] << " " << edg[i][1] << "\n";
cadj[comp[edg[i][0]]].pb(edg[i][1]);
cadj[comp[edg[i][1]]].pb(edg[i][0]);
}
}
prec(1, 0);
for(int i = 1; i < cur; i++) {
ans += 1ll * cmpsz[i] * (cmpsz[i] - 1) * (cmpsz[i] - 2);
}
dfs(1, 0);
cout << ans << "\n";
}
signed main() {
fastio();
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
574 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
574 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
977564 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7772 KB |
Output is correct |
2 |
Correct |
4 ms |
7888 KB |
Output is correct |
3 |
Correct |
4 ms |
7772 KB |
Output is correct |
4 |
Correct |
3 ms |
8028 KB |
Output is correct |
5 |
Correct |
4 ms |
8028 KB |
Output is correct |
6 |
Correct |
4 ms |
7772 KB |
Output is correct |
7 |
Correct |
4 ms |
7916 KB |
Output is correct |
8 |
Correct |
4 ms |
7772 KB |
Output is correct |
9 |
Correct |
4 ms |
7772 KB |
Output is correct |
10 |
Incorrect |
4 ms |
7772 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
14884 KB |
Output is correct |
2 |
Correct |
52 ms |
14676 KB |
Output is correct |
3 |
Correct |
50 ms |
14684 KB |
Output is correct |
4 |
Correct |
51 ms |
14728 KB |
Output is correct |
5 |
Correct |
50 ms |
14684 KB |
Output is correct |
6 |
Correct |
61 ms |
18432 KB |
Output is correct |
7 |
Correct |
59 ms |
17236 KB |
Output is correct |
8 |
Correct |
59 ms |
16464 KB |
Output is correct |
9 |
Correct |
55 ms |
15956 KB |
Output is correct |
10 |
Incorrect |
39 ms |
13648 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7768 KB |
Output is correct |
2 |
Correct |
5 ms |
7772 KB |
Output is correct |
3 |
Runtime error |
577 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
14676 KB |
Output is correct |
2 |
Correct |
51 ms |
14668 KB |
Output is correct |
3 |
Runtime error |
622 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
574 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
574 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |