답안 #714487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
714487 2023-03-24T16:35:16 Z radal 철인 이종 경기 (APIO18_duathlon) C++17
31 / 100
131 ms 30664 KB
#include <bits/stdc++.h>
//#pragma GCC target("sse,sse2,avx2")
#pragma GCC optimize("unroll-loops,O3")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 2e5+20,mod = 998244353;
constexpr ll inf = 1e9+10;
inline int mkay(int a,int b){
    if (a+b >= mod) return a+b-mod;
    if (a+b < 0) return a+b+mod;
    return a+b;
}
 
inline int poww(int a,int k){
    if (k < 0) return 0;
    int z = 1;
    while (k){
        if (k&1) z = 1ll*z*a%mod;
        a = 1ll*a*a%mod;
        k >>= 1;
    } 
    return z; 
}

int n,m;
int h[N],mi[N];
bool cut[N];
int mark[N],sz[N],sum[N];
vector<int> G[N],cp,adj[N];
ll ans;
bool vis[N];


void dfs(int v,int p = -1){
	cp.pb(v);
	mi[v] = h[v];
	int deg = 0;
	for (int u : G[v]){
		if (u == p) continue;
		if (h[u] != -1){
			mi[v] = min(mi[v],h[u]);
		   	continue;
		}
		deg++;
		h[u] = h[v] + 1;
		dfs(u,v);
		mi[v] = min(mi[v],mi[u]);
		if (mi[u] >= h[v] && h[v]) cut[v] = 1;
	}
	if (!h[v] && deg > 1) cut[v] = 1;
}

void dfs2(int v,int c){
	if (cut[v]){
		adj[v].pb(c);
		adj[c].pb(v);
		return;
	}
	mark[v] = c;
	sz[c]++;
	for (int u : G[v]){
		if (!mark[u])
			dfs2(u,c);
	}
}

void dfs3(int v,int p){
	sort(all(adj[v]));
	adj[v].resize(unique(all(adj[v]))-adj[v].begin());
	int s;
	vis[v] = 1;
	if (v > n) s = sz[v];
	else s = 1;
	sum[v] = s;
	ll calc = 0;
	for (int u : adj[v]){
		if (vis[u]) continue;
		if (u == p) continue;
		dfs3(u,v);
		if (v <= n){
			ans += 1ll*s*sum[u]*(cp.size()-1-sum[u]);
			ans += 1ll*s*(s-1)*sum[u];
		}
		else{
			calc += 1ll*sum[u]*(sum[u]-1);
		}
		sum[v] += sum[u];
	}
    if (v > n){
		int tot = cp.size();
		calc += 1ll*+(tot-sum[v])*(tot-sum[v]-1);
		ans += 1ll*s*(tot-1)*(tot-2);
		ans -= 1ll*s*calc;
		for (int u : adj[v]){
			if (u == p) continue;
			ans += 1ll*(tot-sum[u])*(tot-sum[u]-1);
			ans -= (calc - 1ll*sum[u]*(sum[u]-1));
		}
		if (p != -1){
			ans += 1ll*sum[v]*(sum[v]-1);
			ans -= (calc - 1ll*(tot-sum[v])*(tot-sum[v]-1));
		}
    }

	if (v <= n){
		ans += 1ll*s*(cp.size()-sum[v])*(sum[v]-1);
		ans += 1ll*s*(s-1)*(cp.size()-sum[v]);
	}
	//debug(v);
	//debug(ans);
}
int main(){
	ios :: sync_with_stdio(0); cin.tie(0);  cout.tie(0);
	memset(h,-1,sizeof h);
	cin >> n >> m;
	rep(i,0,m){
		int u,v;
		cin >> u >> v;
		G[u].pb(v);
		G[v].pb(u);
	}
	int cur = n+1;
	rep(i,1,n+1){
		if (h[i] != -1) continue;
		cp.clear();
		h[i] = 0;
		dfs(i);
		if ((int)cp.size() < 3) continue;

		int tedb = 0;
		for (int v : cp){
			if (cut[v]){
				for (int u : G[v]) if (cut[u] && h[u] == h[v]+1 && mi[u] == h[u]){
				   	adj[v].pb(u);
					adj[u].pb(v);
				}
				continue;
			}
			if (mark[v]) continue;
			dfs2(v,cur);
			cur++;
			tedb++;
		}
		if (tedb) dfs3(cur-1,-1);
		else dfs3(cp.back(),-1);
	}
	cout << ans << endl;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10452 KB Output is correct
2 Correct 7 ms 10528 KB Output is correct
3 Correct 5 ms 10520 KB Output is correct
4 Correct 6 ms 10452 KB Output is correct
5 Correct 7 ms 10452 KB Output is correct
6 Correct 6 ms 10452 KB Output is correct
7 Incorrect 6 ms 10452 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10452 KB Output is correct
2 Correct 7 ms 10528 KB Output is correct
3 Correct 5 ms 10520 KB Output is correct
4 Correct 6 ms 10452 KB Output is correct
5 Correct 7 ms 10452 KB Output is correct
6 Correct 6 ms 10452 KB Output is correct
7 Incorrect 6 ms 10452 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 24232 KB Output is correct
2 Correct 69 ms 25516 KB Output is correct
3 Correct 80 ms 24260 KB Output is correct
4 Correct 71 ms 24348 KB Output is correct
5 Correct 73 ms 21576 KB Output is correct
6 Correct 96 ms 25076 KB Output is correct
7 Correct 103 ms 20640 KB Output is correct
8 Correct 92 ms 22708 KB Output is correct
9 Correct 76 ms 19380 KB Output is correct
10 Correct 77 ms 20008 KB Output is correct
11 Correct 58 ms 17748 KB Output is correct
12 Correct 66 ms 17532 KB Output is correct
13 Correct 50 ms 17272 KB Output is correct
14 Correct 51 ms 17056 KB Output is correct
15 Correct 39 ms 15976 KB Output is correct
16 Correct 49 ms 15948 KB Output is correct
17 Correct 7 ms 10836 KB Output is correct
18 Correct 10 ms 10836 KB Output is correct
19 Correct 8 ms 10836 KB Output is correct
20 Correct 7 ms 10836 KB Output is correct
21 Correct 8 ms 10896 KB Output is correct
22 Correct 8 ms 10836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10580 KB Output is correct
2 Correct 7 ms 10616 KB Output is correct
3 Correct 7 ms 10620 KB Output is correct
4 Correct 7 ms 10696 KB Output is correct
5 Correct 8 ms 10708 KB Output is correct
6 Correct 8 ms 10608 KB Output is correct
7 Correct 7 ms 10708 KB Output is correct
8 Correct 8 ms 10580 KB Output is correct
9 Correct 10 ms 10580 KB Output is correct
10 Correct 8 ms 10580 KB Output is correct
11 Correct 9 ms 10492 KB Output is correct
12 Correct 7 ms 10580 KB Output is correct
13 Correct 7 ms 10580 KB Output is correct
14 Correct 8 ms 10516 KB Output is correct
15 Correct 7 ms 10580 KB Output is correct
16 Correct 7 ms 10584 KB Output is correct
17 Correct 6 ms 10580 KB Output is correct
18 Correct 9 ms 10580 KB Output is correct
19 Correct 8 ms 10580 KB Output is correct
20 Correct 8 ms 10580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 19152 KB Output is correct
2 Correct 111 ms 19096 KB Output is correct
3 Correct 119 ms 19172 KB Output is correct
4 Correct 94 ms 19108 KB Output is correct
5 Correct 94 ms 19140 KB Output is correct
6 Correct 101 ms 30664 KB Output is correct
7 Correct 103 ms 23296 KB Output is correct
8 Correct 113 ms 22148 KB Output is correct
9 Correct 131 ms 20976 KB Output is correct
10 Correct 101 ms 18916 KB Output is correct
11 Correct 68 ms 19140 KB Output is correct
12 Correct 80 ms 18880 KB Output is correct
13 Correct 70 ms 18876 KB Output is correct
14 Correct 78 ms 18484 KB Output is correct
15 Correct 74 ms 18064 KB Output is correct
16 Correct 46 ms 16048 KB Output is correct
17 Correct 50 ms 19544 KB Output is correct
18 Correct 65 ms 19592 KB Output is correct
19 Correct 56 ms 19784 KB Output is correct
20 Correct 64 ms 19680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 10580 KB Output is correct
2 Correct 5 ms 10580 KB Output is correct
3 Incorrect 6 ms 10580 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 19204 KB Output is correct
2 Correct 97 ms 18972 KB Output is correct
3 Incorrect 94 ms 18460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10452 KB Output is correct
2 Correct 7 ms 10528 KB Output is correct
3 Correct 5 ms 10520 KB Output is correct
4 Correct 6 ms 10452 KB Output is correct
5 Correct 7 ms 10452 KB Output is correct
6 Correct 6 ms 10452 KB Output is correct
7 Incorrect 6 ms 10452 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10452 KB Output is correct
2 Correct 7 ms 10528 KB Output is correct
3 Correct 5 ms 10520 KB Output is correct
4 Correct 6 ms 10452 KB Output is correct
5 Correct 7 ms 10452 KB Output is correct
6 Correct 6 ms 10452 KB Output is correct
7 Incorrect 6 ms 10452 KB Output isn't correct
8 Halted 0 ms 0 KB -