Submission #951481

# Submission time Handle Problem Language Result Execution time Memory
951481 2024-03-22T03:16:32 Z moonrabbit2 Duathlon (APIO18_duathlon) C++17
0 / 100
51 ms 24528 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
using ll=long long;
using pii=array<int,2>;
const int N=200005;
int n,m,u[N],v[N];
ll ans,sz,dp[N];
int V[N], bn, dn, T[N];
vector<pii> G[N];
vector<int> BCC[N], L[N], S;
int GetBCC(int cur, int prev = 0) {
	sz++;
	int ret = V[cur] = ++dn;
	for (auto& [next, edge] : G[cur]) {
		if (next == prev) continue;
		if (V[cur] > V[next]) S.push_back(edge);
		if (V[next]) ret = min(ret, V[next]);
		else {
			int temp = GetBCC(next, cur);
			ret = min(ret, temp);
			if (temp < V[cur]) continue;
			bn++;
			while (1) {
				int t = S.back();
				if(T[u[t]] != bn){
					T[u[t]] = bn;
					BCC[bn].push_back(u[t]);
					L[u[t]].push_back(bn);
				}
				if(T[v[t]] != bn){
					T[v[t]] = bn;
					BCC[bn].push_back(v[t]);
					L[v[t]].push_back(bn);
				}
				S.pop_back();
				if (t == edge) break;
			}
			debug(BCC[bn]);
		}
	}
	return ret;
}
void dfsBCC(int b,int p){
	dp[b]=BCC[b].size();
	for(int u: BCC[b]) if(p!=u){
		ll S=0;
		for(int b2: L[u]){
			if(!dp[b2]){
				dfsBCC(b2,u);
				ans-=(ll)(BCC[b2].size()-1)*(sz+1-dp[b2])*(sz-dp[b2]);
				S+=dp[b2]-1;
				dp[b]+=dp[b2]-1;
			}
		}
		ans-=(BCC[b].size()-1)*(S+1)*S;
	}
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>u[i]>>v[i];
		G[u[i]].push_back({v[i],i});
		G[v[i]].push_back({v[i],i});
	}
	for(int u=1;u<=n;u++) if(!V[u]){
		sz=0;
		GetBCC(u);
		ans+=sz*(sz-1)*(sz-2);
		dfsBCC(bn,0);
	}
	cout<<ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 16984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 16984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 23756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 16988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 24528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 16988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 24524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 16984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 16984 KB Output isn't correct
2 Halted 0 ms 0 KB -