제출 #1265956

#제출 시각아이디문제언어결과실행 시간메모리
1265956thelegendary08철인 이종 경기 (APIO18_duathlon)C++17
100 / 100
135 ms34548 KiB
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vc vector<char>
#define vb vector<bool>
#define mii map<int,int>
#define f0r(i,n) for(int i=0;i<n;i++)
#define FOR(i,k,n) for(int i=k;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define in(a) int a; cin>>a
#define in2(a,b) int a,b; cin>>a>>b
#define in3(a,b,c) int a,b,c; cin>>a>>b>>c
#define in4(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d
#define vin(v,n); vi v(n); f0r(i,n){cin>>v[i];}
#define out(a) cout<<a<<'\n'
#define out2(a,b) cout<<a<<' '<<b<<'\n'
#define out3(a,b,c) cout<<a<<' '<<b<<' '<<c<<'\n'
#define out4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<'\n'
#define pout(a) cout<<a.first<<' '<<a.second<<'\n'
#define vout(v) for(auto u : v){cout<<u<<' ';} cout<<endl
#define dout(a) cout<<a<<' '<<#a<<endl
#define dout2(a,b) cout<<a<<' '<<#a<<' '<<b<<' '<<#b<<endl
#define yn(x); if(x){cout<<"YES"<<'\n';}else{cout<<"NO"<<'\n';}
const int leg = 1e9 + 7;
const int mod = 998244353;
using namespace std;
const int mxn = 1e5 + 5; 
int n,m;
vvi adj(mxn); vi sts(mxn); 
vb vis(mxn); 
int ans = 0, cst = 0; 
vi curcc; 
vvi comps;
stack<int>st; 
int timer = 0; 
vi tin(mxn), ap(mxn), low(mxn); 
void dfs(int node, int from){
	// dout2(node,from);
	tin[node] = low[node] = ++timer; 
	st.push(node); 
	for(auto u : adj[node]){
		if(u == from)continue; 
		if(tin[u]){
			low[node] = min(low[node], tin[u]);
		}
		else{
			dfs(u, node);
			low[node] = min(low[node], low[u]);
			if(low[u] >= tin[node]){
				ap[node] = (tin[node] > 1 || tin[u] > 2);
				comps.pb({node});
				while(comps.back().back() != u){
					comps.back().pb(st.top()); st.pop(); 
				}
			}
		}
	}
}
struct RST{
	vvi adj; 
	int N; vi w, sz; 
	RST(int x){
		w.resize(x); f0r(i,x)w[i] = -1; sz.resize(x); 
		N = x; adj.resize(N); 
	}
	
	void ins_edge(int a, int b){
		adj[a].pb(b); adj[b].pb(a); 
	}
	
	void dfs(int node, int from){
		sz[node] = (node < n); 
		for(auto u : adj[node]){
			if(u != from){
				dfs(u, node); 
				ans += 2 * w[node] * sz[node] * sz[u]; 
				sz[node] += sz[u]; 
			}
		}
		ans += 2 * w[node] * (timer - sz[node]) * sz[node]; 
	}
};	
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//ifstream cin(".in");
	//ofstream cout(".out");
	cin>>n>>m;
	f0r(i, m){
		in2(a,b); a--; b--; 
		adj[a].pb(b); adj[b].pb(a); 
	}
	if(n == 1 || n == 2){ out(0); return 0; }
	RST R = RST(2 * n + 5); 
	int id = n; 
	f0r(i, n){
		if(tin[i] == 0){
			timer = 0; 
			comps.clear(); st = stack<int>();
			dfs(i, -1);
			
			
			// dout2(timer, comps.size());
			
		
			
			for(auto u : comps){
				R.w[id] = u.size(); 
				// vout(u);
				for(auto v : u){
					R.ins_edge(v, id);
				}
				id++; 
			}
			
			
			R.dfs(i, -1);
			
		}
	}
	
	out(ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...