//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define N 200015
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
int n,m,dfn[N],low[N],sz[N],have[N],nbcc=0,t=0,ans=0;
bool vis[N];
stack<int>st;
vector<int>g[N],bcc[N];
vector<int>G[N];
void tarjan(int p,int lp){
dfn[p]=low[p]=++t;
st.push(p);
for (auto i:g[p]){
if (!dfn[i]){
tarjan(i,p);
low[p]=min(low[p],low[i]);
if (dfn[p]<=low[p]){
nbcc++;
for (int x=0;x!=i;st.pop()){
x=st.top();
bcc[nbcc].push_back(x);
}
bcc[nbcc].push_back(p);
}
}
else if (i!=lp&&dfn[i]<dfn[p])
low[p]=min(low[p],dfn[i]);
}
}
void build(){
for (int i=1;i<=nbcc;i++){
for (auto j:bcc[i]){
G[i+n].push_back(j);
G[j].push_back(i+n);
}
}
}
void dfs(int p,int lp){
vis[p]=1; sz[p]+=(p<=n);
for (auto i:G[p]){
if (i!=lp){
dfs(i,p);
ans=(ans+have[p]*sz[i]*(sz[p]));
sz[p]+=sz[i];
}
}
ans=(ans+have[p]*(n-sz[p])*sz[p]);
}
signed main(){
fast
cin>>n>>m;
for (int i=1;i<=m;i++){
int a,b; cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
for (int i=1;i<=n;i++){
have[i]=-1;
if (!dfn[i]){
while (!st.empty()) st.pop();
tarjan(i,0);
}
}
build();
for (int i=1;i<=nbcc;i++)
have[i+n]=bcc[i].size();
for (int i=1;i<=n+nbcc;i++){
if (!vis[i]){
dfs(i,0);
}
}
cout<<ans*2<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
14420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
14420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
37484 KB |
Output is correct |
2 |
Correct |
79 ms |
37740 KB |
Output is correct |
3 |
Incorrect |
94 ms |
36308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14572 KB |
Output is correct |
2 |
Correct |
8 ms |
14548 KB |
Output is correct |
3 |
Correct |
9 ms |
14548 KB |
Output is correct |
4 |
Correct |
9 ms |
14676 KB |
Output is correct |
5 |
Correct |
8 ms |
14688 KB |
Output is correct |
6 |
Correct |
10 ms |
14676 KB |
Output is correct |
7 |
Correct |
8 ms |
14676 KB |
Output is correct |
8 |
Correct |
8 ms |
14676 KB |
Output is correct |
9 |
Correct |
9 ms |
14676 KB |
Output is correct |
10 |
Incorrect |
8 ms |
14548 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
34012 KB |
Output is correct |
2 |
Correct |
95 ms |
34280 KB |
Output is correct |
3 |
Correct |
107 ms |
34260 KB |
Output is correct |
4 |
Correct |
108 ms |
34272 KB |
Output is correct |
5 |
Correct |
108 ms |
34252 KB |
Output is correct |
6 |
Correct |
103 ms |
41568 KB |
Output is correct |
7 |
Correct |
109 ms |
39524 KB |
Output is correct |
8 |
Correct |
107 ms |
38196 KB |
Output is correct |
9 |
Correct |
109 ms |
36788 KB |
Output is correct |
10 |
Incorrect |
103 ms |
34224 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14548 KB |
Output is correct |
2 |
Correct |
8 ms |
14568 KB |
Output is correct |
3 |
Incorrect |
9 ms |
14596 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
34016 KB |
Output is correct |
2 |
Correct |
99 ms |
33868 KB |
Output is correct |
3 |
Incorrect |
127 ms |
33212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
14420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
14420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |