#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN=1e5;
int n, m, dt=1, tin[mxN], low[mxN], st[mxN], sth, bccI;
vector<int> adj1[mxN], adj2[2*mxN];
ll sz[2*mxN], n2, ans;
void dfs1(int u, int p) {
tin[u]=low[u]=dt++;
st[sth++]=u;
++n2;
for(int v : adj1[u]) {
if(!tin[v]) {
dfs1(v, u);
low[u]=min(low[v], low[u]);
if(low[v]>=tin[u]) {
adj2[u].push_back(bccI+n);
while(st[sth-1]!=u)
adj2[bccI+n].push_back(st[--sth]);
++bccI;
}
} else if(v!=p)
low[u]=min(tin[v], low[u]);
}
}
void dfs2(int u, int p) {
// cout << "d21 " << u << " " << p << endl;
sz[u]=u<n;
for(int v : adj2[u]) {
dfs2(v, u);
sz[u]+=sz[v];
if(u>=n)
ans-=(adj2[u].size()-(p==-1))*sz[v]*(sz[v]-1);
}
if(u>=n)
ans-=adj2[u].size()*(n2-sz[u])*(n2-sz[u]-1);
// cout << "d29 " << u << " " << p << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
while(m--) {
int u, v;
cin >> u >> v, --u, --v;
adj1[u].push_back(v);
adj1[v].push_back(u);
}
for(int i=0; i<n; ++i) {
if(tin[i])
continue;
dfs1(i, -1);
ans+=n2*(n2-1)*(n2-2);
dfs2(i, -1);
n2=0;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7524 KB |
Output is correct |
3 |
Correct |
8 ms |
7524 KB |
Output is correct |
4 |
Correct |
8 ms |
7524 KB |
Output is correct |
5 |
Correct |
7 ms |
7532 KB |
Output is correct |
6 |
Correct |
10 ms |
7552 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7552 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7524 KB |
Output is correct |
3 |
Correct |
8 ms |
7524 KB |
Output is correct |
4 |
Correct |
8 ms |
7524 KB |
Output is correct |
5 |
Correct |
7 ms |
7532 KB |
Output is correct |
6 |
Correct |
10 ms |
7552 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7552 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
22516 KB |
Output is correct |
2 |
Correct |
145 ms |
22656 KB |
Output is correct |
3 |
Correct |
155 ms |
22836 KB |
Output is correct |
4 |
Correct |
130 ms |
22836 KB |
Output is correct |
5 |
Correct |
143 ms |
22836 KB |
Output is correct |
6 |
Correct |
161 ms |
22836 KB |
Output is correct |
7 |
Correct |
126 ms |
22836 KB |
Output is correct |
8 |
Correct |
116 ms |
22836 KB |
Output is correct |
9 |
Correct |
104 ms |
22836 KB |
Output is correct |
10 |
Correct |
169 ms |
22836 KB |
Output is correct |
11 |
Correct |
99 ms |
22836 KB |
Output is correct |
12 |
Correct |
121 ms |
22836 KB |
Output is correct |
13 |
Correct |
107 ms |
22836 KB |
Output is correct |
14 |
Correct |
100 ms |
22836 KB |
Output is correct |
15 |
Correct |
77 ms |
22836 KB |
Output is correct |
16 |
Correct |
94 ms |
22836 KB |
Output is correct |
17 |
Correct |
10 ms |
22836 KB |
Output is correct |
18 |
Correct |
12 ms |
22836 KB |
Output is correct |
19 |
Correct |
11 ms |
22836 KB |
Output is correct |
20 |
Correct |
11 ms |
22836 KB |
Output is correct |
21 |
Correct |
11 ms |
22836 KB |
Output is correct |
22 |
Correct |
13 ms |
22836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
22836 KB |
Output is correct |
2 |
Correct |
9 ms |
22836 KB |
Output is correct |
3 |
Correct |
9 ms |
22836 KB |
Output is correct |
4 |
Correct |
9 ms |
22836 KB |
Output is correct |
5 |
Correct |
11 ms |
22836 KB |
Output is correct |
6 |
Correct |
8 ms |
22836 KB |
Output is correct |
7 |
Correct |
10 ms |
22836 KB |
Output is correct |
8 |
Correct |
8 ms |
22836 KB |
Output is correct |
9 |
Correct |
8 ms |
22836 KB |
Output is correct |
10 |
Correct |
8 ms |
22836 KB |
Output is correct |
11 |
Correct |
10 ms |
22836 KB |
Output is correct |
12 |
Correct |
8 ms |
22836 KB |
Output is correct |
13 |
Correct |
8 ms |
22836 KB |
Output is correct |
14 |
Correct |
12 ms |
22836 KB |
Output is correct |
15 |
Correct |
8 ms |
22836 KB |
Output is correct |
16 |
Correct |
7 ms |
22836 KB |
Output is correct |
17 |
Correct |
9 ms |
22836 KB |
Output is correct |
18 |
Correct |
9 ms |
22836 KB |
Output is correct |
19 |
Correct |
9 ms |
22836 KB |
Output is correct |
20 |
Correct |
9 ms |
22836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
22836 KB |
Output is correct |
2 |
Correct |
155 ms |
22836 KB |
Output is correct |
3 |
Correct |
136 ms |
22836 KB |
Output is correct |
4 |
Correct |
149 ms |
22836 KB |
Output is correct |
5 |
Correct |
128 ms |
22836 KB |
Output is correct |
6 |
Correct |
219 ms |
28080 KB |
Output is correct |
7 |
Correct |
150 ms |
28080 KB |
Output is correct |
8 |
Correct |
173 ms |
28080 KB |
Output is correct |
9 |
Correct |
160 ms |
28080 KB |
Output is correct |
10 |
Correct |
169 ms |
28080 KB |
Output is correct |
11 |
Correct |
152 ms |
28080 KB |
Output is correct |
12 |
Correct |
144 ms |
28080 KB |
Output is correct |
13 |
Correct |
151 ms |
28080 KB |
Output is correct |
14 |
Correct |
112 ms |
28080 KB |
Output is correct |
15 |
Correct |
117 ms |
28080 KB |
Output is correct |
16 |
Correct |
61 ms |
28080 KB |
Output is correct |
17 |
Correct |
76 ms |
28080 KB |
Output is correct |
18 |
Correct |
88 ms |
28080 KB |
Output is correct |
19 |
Correct |
91 ms |
28080 KB |
Output is correct |
20 |
Correct |
95 ms |
28080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
28080 KB |
Output is correct |
2 |
Correct |
8 ms |
28080 KB |
Output is correct |
3 |
Incorrect |
8 ms |
28080 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
28080 KB |
Output is correct |
2 |
Correct |
177 ms |
28080 KB |
Output is correct |
3 |
Incorrect |
135 ms |
28080 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7524 KB |
Output is correct |
3 |
Correct |
8 ms |
7524 KB |
Output is correct |
4 |
Correct |
8 ms |
7524 KB |
Output is correct |
5 |
Correct |
7 ms |
7532 KB |
Output is correct |
6 |
Correct |
10 ms |
7552 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7552 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7524 KB |
Output is correct |
3 |
Correct |
8 ms |
7524 KB |
Output is correct |
4 |
Correct |
8 ms |
7524 KB |
Output is correct |
5 |
Correct |
7 ms |
7532 KB |
Output is correct |
6 |
Correct |
10 ms |
7552 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7552 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |