답안 #739176

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
739176 2023-05-10T06:19:23 Z 089487 철인 이종 경기 (APIO18_duathlon) C++14
62 / 100
1000 ms 42440 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include<bits/stdc++.h>
#define int long long
#define quick ios::sync_with_stdio(0);cin.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define repd(x,a,b) for(int x=a;x>=b;x--)
#define lowbit(x) (x&-x)
#define sz(x) (int)(x.size())
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define mp make_pair
#define eb emplace_back
using namespace std;
typedef pair<int,int> pii;
void debug(){
    cout<<"\n";
}
template <class T,class ... U >
void debug(T a, U ... b){
    cout<<a<<" ",debug(b...);
}
const int N=2e5+7;
const int INF=1e18;
vector<int> v[N];
vector<int> v2[N];
vector<int> v3[N];
int in[N];
int low[N];
int t=1;
int num;
int sz[N];
bool cut[N];
stack<int> st;
void add_edge(int a,int b){
	v2[a].eb(b);
	v2[b].eb(a);
	//debug(a,"<->",b);
}
void dfs(int x,int p=-1){
	in[x]=low[x]=t++;
	st.push(x);
	bool ct=false;
	for(int i:v[x]){
		if(i==p) continue;
		if(in[i]) low[x]=min(low[x],in[i]);
		else{
			dfs(i,x);
			if(in[x]<=low[i]) ct=true;
			low[x]=min(low[x],low[i]);
		}
	}
	if(p==-1){
		ct=(sz(v[x])>=2);
	}
	if(p==-1||in[p]<=low[x]){
		++num;
		while(sz(st)){
			int x2=st.top();
			st.pop();
			add_edge(num,x2);
			if(x2==x) break;
		}
		if(p!=-1)add_edge(num,p);
		cut[num]=ct;
	}
}
pii e[N];
int sum;
int n;
int Sz[N];
int Sz2[N];
bool vis[N];
int fa[N];
int dep[N];
void dfs_sz(int x,int p=-1,int d=0){
	dep[x]=d;
	Sz[x]=sz[x];
	for(int i:v2[x]){
		if(i!=p){
			dfs_sz(i,x,d+1);
			Sz[x]+=Sz[i];
		}
	}
	sum=Sz[x];
}
int C2(int x){
	if(x<2) return 0;
	return x*(x-1);
}
int C3(int x){
	if(x<3) return 0;
	return x*(x-1)*(x-2);
}
int ans=0;
void solve(int x,int p=-1){
	fa[x]=p;
	vis[x]=true;
	for(int i:v2[x]){
		if(!vis[i]) solve(i,x);
	}
	if(x<=n){
		int s=0;
 
		// 1
		for(int i:v2[x]){
			int S2;
						
			if(i==p){
				S2=sum-Sz[x];
			}
			else{
				S2=Sz[i];	
			}
			ans+=s*S2*2;
			s+=S2;
			//ans+=C2(S2);
		}
		/*for(int i:v2[x]){
			for(int j:v2[i]){
				if(j==x) continue;
				int S2;
				if(dep[j]<dep[i]){
					S2=sum-Sz[j];
				}
				else{
 
				}
			}
		}*/
	}
	else{
		int l=sz(v2[x]);
		for(int i:v2[x]){
			int S2;
			if(i==p){
				S2=sum-Sz[x];
			}
			else{
				S2=Sz[i];
			}
			for(int j:v2[x]){
				int S3;
				if(i==j) continue;
				if(j==p){
					S3=sum-Sz[x];
				}
				else{
					S3=Sz[j];
				}
				ans+=S2*S3*(l-2);
			}
		}	
	}
}
signed main(){
	quick
	int m;
	cin>>n>>m;
	rep(i,1,m){
		cin>>e[i].F>>e[i].S;
		v[e[i].F].eb(e[i].S);
		v[e[i].S].eb(e[i].F);
	}
	num=n;
	rep(i,1,n) sz[i]=1;
	rep(i,1,n){
		if(!in[i]) dfs(i);
	}
	ans=0;
	rep(i,1,num){
		if(!vis[i]){
			dfs_sz(i);
			solve(i);
		}
	}
	//rep(i,1,n) cout<<Sz[i]<<" \n"[i==n];
	cout<<ans<<"\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 9 ms 14376 KB Output is correct
3 Correct 10 ms 14428 KB Output is correct
4 Correct 10 ms 14424 KB Output is correct
5 Correct 9 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 9 ms 14448 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 11 ms 14420 KB Output is correct
10 Correct 8 ms 14428 KB Output is correct
11 Correct 8 ms 14432 KB Output is correct
12 Correct 8 ms 14372 KB Output is correct
13 Correct 9 ms 14436 KB Output is correct
14 Correct 9 ms 14468 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 9 ms 14424 KB Output is correct
17 Correct 11 ms 14420 KB Output is correct
18 Correct 8 ms 14412 KB Output is correct
19 Correct 9 ms 14556 KB Output is correct
20 Correct 9 ms 14420 KB Output is correct
21 Correct 10 ms 14420 KB Output is correct
22 Correct 9 ms 14412 KB Output is correct
23 Correct 9 ms 14404 KB Output is correct
24 Correct 9 ms 14424 KB Output is correct
25 Correct 8 ms 14384 KB Output is correct
26 Correct 9 ms 14420 KB Output is correct
27 Correct 8 ms 14424 KB Output is correct
28 Correct 9 ms 14420 KB Output is correct
29 Correct 9 ms 14420 KB Output is correct
30 Correct 9 ms 14428 KB Output is correct
31 Correct 10 ms 14400 KB Output is correct
32 Correct 9 ms 14432 KB Output is correct
33 Correct 9 ms 14420 KB Output is correct
34 Correct 11 ms 14420 KB Output is correct
35 Correct 13 ms 14424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 9 ms 14376 KB Output is correct
3 Correct 10 ms 14428 KB Output is correct
4 Correct 10 ms 14424 KB Output is correct
5 Correct 9 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 9 ms 14448 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 11 ms 14420 KB Output is correct
10 Correct 8 ms 14428 KB Output is correct
11 Correct 8 ms 14432 KB Output is correct
12 Correct 8 ms 14372 KB Output is correct
13 Correct 9 ms 14436 KB Output is correct
14 Correct 9 ms 14468 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 9 ms 14424 KB Output is correct
17 Correct 11 ms 14420 KB Output is correct
18 Correct 8 ms 14412 KB Output is correct
19 Correct 9 ms 14556 KB Output is correct
20 Correct 9 ms 14420 KB Output is correct
21 Correct 10 ms 14420 KB Output is correct
22 Correct 9 ms 14412 KB Output is correct
23 Correct 9 ms 14404 KB Output is correct
24 Correct 9 ms 14424 KB Output is correct
25 Correct 8 ms 14384 KB Output is correct
26 Correct 9 ms 14420 KB Output is correct
27 Correct 8 ms 14424 KB Output is correct
28 Correct 9 ms 14420 KB Output is correct
29 Correct 9 ms 14420 KB Output is correct
30 Correct 9 ms 14428 KB Output is correct
31 Correct 10 ms 14400 KB Output is correct
32 Correct 9 ms 14432 KB Output is correct
33 Correct 9 ms 14420 KB Output is correct
34 Correct 11 ms 14420 KB Output is correct
35 Correct 13 ms 14424 KB Output is correct
36 Correct 9 ms 14384 KB Output is correct
37 Correct 9 ms 14436 KB Output is correct
38 Correct 8 ms 14428 KB Output is correct
39 Correct 8 ms 14420 KB Output is correct
40 Correct 9 ms 14420 KB Output is correct
41 Correct 9 ms 14420 KB Output is correct
42 Correct 8 ms 14420 KB Output is correct
43 Correct 8 ms 14480 KB Output is correct
44 Correct 10 ms 14428 KB Output is correct
45 Correct 9 ms 14464 KB Output is correct
46 Correct 9 ms 14464 KB Output is correct
47 Correct 10 ms 14432 KB Output is correct
48 Correct 9 ms 14416 KB Output is correct
49 Correct 8 ms 14428 KB Output is correct
50 Correct 8 ms 14420 KB Output is correct
51 Correct 8 ms 14396 KB Output is correct
52 Correct 9 ms 14548 KB Output is correct
53 Correct 10 ms 14420 KB Output is correct
54 Correct 8 ms 14424 KB Output is correct
55 Correct 9 ms 14392 KB Output is correct
56 Correct 8 ms 14420 KB Output is correct
57 Correct 8 ms 14420 KB Output is correct
58 Correct 8 ms 14428 KB Output is correct
59 Correct 9 ms 14428 KB Output is correct
60 Correct 8 ms 14420 KB Output is correct
61 Correct 9 ms 14424 KB Output is correct
62 Correct 11 ms 14452 KB Output is correct
63 Correct 9 ms 14420 KB Output is correct
64 Correct 8 ms 14420 KB Output is correct
65 Correct 9 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1073 ms 41568 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14676 KB Output is correct
2 Correct 11 ms 14676 KB Output is correct
3 Correct 9 ms 14580 KB Output is correct
4 Correct 10 ms 14780 KB Output is correct
5 Correct 13 ms 14804 KB Output is correct
6 Correct 9 ms 14676 KB Output is correct
7 Correct 11 ms 14676 KB Output is correct
8 Correct 11 ms 14728 KB Output is correct
9 Correct 12 ms 14676 KB Output is correct
10 Correct 9 ms 14676 KB Output is correct
11 Correct 9 ms 14684 KB Output is correct
12 Correct 11 ms 14636 KB Output is correct
13 Correct 10 ms 14560 KB Output is correct
14 Correct 9 ms 14564 KB Output is correct
15 Correct 10 ms 14548 KB Output is correct
16 Correct 9 ms 14548 KB Output is correct
17 Correct 9 ms 14676 KB Output is correct
18 Correct 9 ms 14676 KB Output is correct
19 Correct 12 ms 14804 KB Output is correct
20 Correct 9 ms 14632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 35188 KB Output is correct
2 Correct 132 ms 35124 KB Output is correct
3 Correct 135 ms 35192 KB Output is correct
4 Correct 108 ms 35208 KB Output is correct
5 Correct 124 ms 35092 KB Output is correct
6 Correct 117 ms 42440 KB Output is correct
7 Correct 136 ms 40396 KB Output is correct
8 Correct 134 ms 39012 KB Output is correct
9 Correct 153 ms 37656 KB Output is correct
10 Correct 150 ms 35192 KB Output is correct
11 Correct 123 ms 35084 KB Output is correct
12 Correct 130 ms 35112 KB Output is correct
13 Correct 128 ms 35148 KB Output is correct
14 Correct 106 ms 34544 KB Output is correct
15 Correct 87 ms 33840 KB Output is correct
16 Correct 66 ms 31960 KB Output is correct
17 Correct 103 ms 35552 KB Output is correct
18 Correct 88 ms 35512 KB Output is correct
19 Correct 79 ms 35808 KB Output is correct
20 Correct 74 ms 35516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14676 KB Output is correct
2 Correct 9 ms 14628 KB Output is correct
3 Correct 9 ms 14564 KB Output is correct
4 Correct 9 ms 14548 KB Output is correct
5 Correct 10 ms 14552 KB Output is correct
6 Correct 9 ms 14556 KB Output is correct
7 Correct 9 ms 14548 KB Output is correct
8 Correct 12 ms 14564 KB Output is correct
9 Correct 10 ms 14560 KB Output is correct
10 Correct 10 ms 14564 KB Output is correct
11 Correct 9 ms 14548 KB Output is correct
12 Correct 9 ms 14732 KB Output is correct
13 Correct 8 ms 14676 KB Output is correct
14 Correct 9 ms 14676 KB Output is correct
15 Correct 11 ms 14676 KB Output is correct
16 Correct 9 ms 14548 KB Output is correct
17 Correct 9 ms 14548 KB Output is correct
18 Correct 9 ms 14572 KB Output is correct
19 Correct 9 ms 14548 KB Output is correct
20 Correct 9 ms 14548 KB Output is correct
21 Correct 10 ms 14560 KB Output is correct
22 Correct 9 ms 14676 KB Output is correct
23 Correct 10 ms 14676 KB Output is correct
24 Correct 10 ms 14564 KB Output is correct
25 Correct 9 ms 14548 KB Output is correct
26 Correct 9 ms 14548 KB Output is correct
27 Correct 9 ms 14548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 35076 KB Output is correct
2 Correct 108 ms 34864 KB Output is correct
3 Correct 110 ms 34816 KB Output is correct
4 Correct 108 ms 33612 KB Output is correct
5 Correct 138 ms 32048 KB Output is correct
6 Correct 96 ms 31120 KB Output is correct
7 Correct 94 ms 30880 KB Output is correct
8 Correct 86 ms 30332 KB Output is correct
9 Correct 88 ms 30148 KB Output is correct
10 Correct 92 ms 29988 KB Output is correct
11 Correct 95 ms 29772 KB Output is correct
12 Correct 154 ms 29852 KB Output is correct
13 Correct 253 ms 29836 KB Output is correct
14 Execution timed out 1069 ms 32608 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 9 ms 14376 KB Output is correct
3 Correct 10 ms 14428 KB Output is correct
4 Correct 10 ms 14424 KB Output is correct
5 Correct 9 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 9 ms 14448 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 11 ms 14420 KB Output is correct
10 Correct 8 ms 14428 KB Output is correct
11 Correct 8 ms 14432 KB Output is correct
12 Correct 8 ms 14372 KB Output is correct
13 Correct 9 ms 14436 KB Output is correct
14 Correct 9 ms 14468 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 9 ms 14424 KB Output is correct
17 Correct 11 ms 14420 KB Output is correct
18 Correct 8 ms 14412 KB Output is correct
19 Correct 9 ms 14556 KB Output is correct
20 Correct 9 ms 14420 KB Output is correct
21 Correct 10 ms 14420 KB Output is correct
22 Correct 9 ms 14412 KB Output is correct
23 Correct 9 ms 14404 KB Output is correct
24 Correct 9 ms 14424 KB Output is correct
25 Correct 8 ms 14384 KB Output is correct
26 Correct 9 ms 14420 KB Output is correct
27 Correct 8 ms 14424 KB Output is correct
28 Correct 9 ms 14420 KB Output is correct
29 Correct 9 ms 14420 KB Output is correct
30 Correct 9 ms 14428 KB Output is correct
31 Correct 10 ms 14400 KB Output is correct
32 Correct 9 ms 14432 KB Output is correct
33 Correct 9 ms 14420 KB Output is correct
34 Correct 11 ms 14420 KB Output is correct
35 Correct 13 ms 14424 KB Output is correct
36 Correct 9 ms 14384 KB Output is correct
37 Correct 9 ms 14436 KB Output is correct
38 Correct 8 ms 14428 KB Output is correct
39 Correct 8 ms 14420 KB Output is correct
40 Correct 9 ms 14420 KB Output is correct
41 Correct 9 ms 14420 KB Output is correct
42 Correct 8 ms 14420 KB Output is correct
43 Correct 8 ms 14480 KB Output is correct
44 Correct 10 ms 14428 KB Output is correct
45 Correct 9 ms 14464 KB Output is correct
46 Correct 9 ms 14464 KB Output is correct
47 Correct 10 ms 14432 KB Output is correct
48 Correct 9 ms 14416 KB Output is correct
49 Correct 8 ms 14428 KB Output is correct
50 Correct 8 ms 14420 KB Output is correct
51 Correct 8 ms 14396 KB Output is correct
52 Correct 9 ms 14548 KB Output is correct
53 Correct 10 ms 14420 KB Output is correct
54 Correct 8 ms 14424 KB Output is correct
55 Correct 9 ms 14392 KB Output is correct
56 Correct 8 ms 14420 KB Output is correct
57 Correct 8 ms 14420 KB Output is correct
58 Correct 8 ms 14428 KB Output is correct
59 Correct 9 ms 14428 KB Output is correct
60 Correct 8 ms 14420 KB Output is correct
61 Correct 9 ms 14424 KB Output is correct
62 Correct 11 ms 14452 KB Output is correct
63 Correct 9 ms 14420 KB Output is correct
64 Correct 8 ms 14420 KB Output is correct
65 Correct 9 ms 14428 KB Output is correct
66 Correct 9 ms 14548 KB Output is correct
67 Correct 10 ms 14564 KB Output is correct
68 Correct 11 ms 14800 KB Output is correct
69 Correct 10 ms 14676 KB Output is correct
70 Correct 13 ms 14756 KB Output is correct
71 Correct 10 ms 14548 KB Output is correct
72 Correct 9 ms 14548 KB Output is correct
73 Correct 9 ms 14548 KB Output is correct
74 Correct 9 ms 14548 KB Output is correct
75 Correct 9 ms 14548 KB Output is correct
76 Correct 8 ms 14420 KB Output is correct
77 Correct 9 ms 14676 KB Output is correct
78 Correct 9 ms 14552 KB Output is correct
79 Correct 9 ms 14580 KB Output is correct
80 Correct 9 ms 14548 KB Output is correct
81 Correct 9 ms 14636 KB Output is correct
82 Correct 10 ms 14676 KB Output is correct
83 Correct 11 ms 14676 KB Output is correct
84 Correct 9 ms 14564 KB Output is correct
85 Correct 9 ms 14676 KB Output is correct
86 Correct 9 ms 14556 KB Output is correct
87 Correct 10 ms 14548 KB Output is correct
88 Correct 10 ms 14548 KB Output is correct
89 Correct 9 ms 14560 KB Output is correct
90 Correct 9 ms 14548 KB Output is correct
91 Correct 10 ms 14564 KB Output is correct
92 Correct 9 ms 14548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 9 ms 14376 KB Output is correct
3 Correct 10 ms 14428 KB Output is correct
4 Correct 10 ms 14424 KB Output is correct
5 Correct 9 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 9 ms 14448 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 11 ms 14420 KB Output is correct
10 Correct 8 ms 14428 KB Output is correct
11 Correct 8 ms 14432 KB Output is correct
12 Correct 8 ms 14372 KB Output is correct
13 Correct 9 ms 14436 KB Output is correct
14 Correct 9 ms 14468 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 9 ms 14424 KB Output is correct
17 Correct 11 ms 14420 KB Output is correct
18 Correct 8 ms 14412 KB Output is correct
19 Correct 9 ms 14556 KB Output is correct
20 Correct 9 ms 14420 KB Output is correct
21 Correct 10 ms 14420 KB Output is correct
22 Correct 9 ms 14412 KB Output is correct
23 Correct 9 ms 14404 KB Output is correct
24 Correct 9 ms 14424 KB Output is correct
25 Correct 8 ms 14384 KB Output is correct
26 Correct 9 ms 14420 KB Output is correct
27 Correct 8 ms 14424 KB Output is correct
28 Correct 9 ms 14420 KB Output is correct
29 Correct 9 ms 14420 KB Output is correct
30 Correct 9 ms 14428 KB Output is correct
31 Correct 10 ms 14400 KB Output is correct
32 Correct 9 ms 14432 KB Output is correct
33 Correct 9 ms 14420 KB Output is correct
34 Correct 11 ms 14420 KB Output is correct
35 Correct 13 ms 14424 KB Output is correct
36 Correct 9 ms 14384 KB Output is correct
37 Correct 9 ms 14436 KB Output is correct
38 Correct 8 ms 14428 KB Output is correct
39 Correct 8 ms 14420 KB Output is correct
40 Correct 9 ms 14420 KB Output is correct
41 Correct 9 ms 14420 KB Output is correct
42 Correct 8 ms 14420 KB Output is correct
43 Correct 8 ms 14480 KB Output is correct
44 Correct 10 ms 14428 KB Output is correct
45 Correct 9 ms 14464 KB Output is correct
46 Correct 9 ms 14464 KB Output is correct
47 Correct 10 ms 14432 KB Output is correct
48 Correct 9 ms 14416 KB Output is correct
49 Correct 8 ms 14428 KB Output is correct
50 Correct 8 ms 14420 KB Output is correct
51 Correct 8 ms 14396 KB Output is correct
52 Correct 9 ms 14548 KB Output is correct
53 Correct 10 ms 14420 KB Output is correct
54 Correct 8 ms 14424 KB Output is correct
55 Correct 9 ms 14392 KB Output is correct
56 Correct 8 ms 14420 KB Output is correct
57 Correct 8 ms 14420 KB Output is correct
58 Correct 8 ms 14428 KB Output is correct
59 Correct 9 ms 14428 KB Output is correct
60 Correct 8 ms 14420 KB Output is correct
61 Correct 9 ms 14424 KB Output is correct
62 Correct 11 ms 14452 KB Output is correct
63 Correct 9 ms 14420 KB Output is correct
64 Correct 8 ms 14420 KB Output is correct
65 Correct 9 ms 14428 KB Output is correct
66 Execution timed out 1073 ms 41568 KB Time limit exceeded
67 Halted 0 ms 0 KB -