#include <bits/stdc++.h>
#define N 100005
using namespace std;
vector<int> adj[N];
vector<int> adj2[N];
vector<int> adj3[N];
int d[N];
int low[N];
vector<pair<int,int>> edges;
void dfs(int v,int par){
d[v] = d[par] + 1;
low[v] = d[v];
for(auto u:adj[v]){
if(u == par)
continue;
if(d[u] != 0){
low[v] = min(d[u],low[v]);
if(d[v] < d[u]){
adj2[v].push_back(u);
adj2[u].push_back(v);
}
}
else{
dfs(u,v);
low[v] = min(low[v],low[u]);
if(low[u] <= d[v]){
adj2[v].push_back(u);
adj2[u].push_back(v);
}
else{
edges.push_back({u,v});
}
}
}
}
int cnt[N];
int group[N];
int sub[N];
int n;
long long ans = 0;
void dfs2(int v){
cnt[group[v]]++;
for(auto u:adj2[v]){
if(group[u])continue;
group[u] = group[v];
dfs2(u);
}
}
void dfs3(int v,int par){
sub[v] = cnt[v];
for(auto u:adj3[v]){
if(u == par)
continue;
dfs3(u,v);
sub[v] += sub[u];
}
ans += 2 * (long long)cnt[v] * (cnt[v] - 1) * (n - cnt[v]);
ans -= 2 * (long long)(cnt[v] - 1) * (n - cnt[v]);
for(auto u:adj3[v]){
if(u == par){
ans += (long long)cnt[v] * (n - sub[v]) * (sub[v] - cnt[v]);
}
else{
ans += (long long)cnt[v] * (n - sub[u] - cnt[v]) * (sub[u]);
}
}
}
void solve(){
int m;
cin >> n >> m;
for(int i = 1;i<=m;i++){
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 1;i<=n;i++){
if(d[i] == 0)
dfs(i,0);
}
for(int i = 1;i<=n;i++){
if(group[i] == 0){
group[i] = i;
dfs2(i);
ans += (long long)cnt[i] * (cnt[i]-1) * (cnt[i]-2);
}
}
for(auto u:edges){
adj3[group[u.first]].push_back(group[u.second]);
adj3[group[u.second]].push_back(group[u.first]);
}
for(int i = 1;i<=n;i++){
if(sub[i] == 0 && group[i] == i)
dfs3(i,0);
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
25712 KB |
Output is correct |
2 |
Correct |
48 ms |
25676 KB |
Output is correct |
3 |
Incorrect |
51 ms |
21316 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
3 ms |
7472 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
3 ms |
7508 KB |
Output is correct |
5 |
Correct |
3 ms |
7508 KB |
Output is correct |
6 |
Correct |
3 ms |
7508 KB |
Output is correct |
7 |
Correct |
3 ms |
7508 KB |
Output is correct |
8 |
Correct |
3 ms |
7508 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Incorrect |
3 ms |
7380 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
16492 KB |
Output is correct |
2 |
Correct |
48 ms |
16536 KB |
Output is correct |
3 |
Correct |
43 ms |
16576 KB |
Output is correct |
4 |
Correct |
44 ms |
16504 KB |
Output is correct |
5 |
Correct |
44 ms |
16576 KB |
Output is correct |
6 |
Correct |
48 ms |
22216 KB |
Output is correct |
7 |
Correct |
48 ms |
20264 KB |
Output is correct |
8 |
Correct |
46 ms |
19220 KB |
Output is correct |
9 |
Correct |
49 ms |
18308 KB |
Output is correct |
10 |
Incorrect |
44 ms |
16468 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
16576 KB |
Output is correct |
2 |
Correct |
51 ms |
16372 KB |
Output is correct |
3 |
Incorrect |
67 ms |
16728 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |