답안 #1007746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007746 2024-06-25T12:31:48 Z amirhoseinfar1385 철인 이종 경기 (APIO18_duathlon) C++17
0 / 100
51 ms 33992 KB
#include<bits/stdc++.h>
using namespace std;
const long long maxn=200000+10;
vector<long long>adj[maxn],fakeadj[maxn],unnow;
long long n,m,vis[maxn],high[maxn],sz[maxn],newnode,low[maxn],wh[maxn],timea;

void vorod(){
	cin>>n>>m;
	for(long long i=0;i<m;i++){
		long long u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
}

void predfs(long long u){
	if(vis[u]==1){
		return ;
	}
	vis[u]=1;
	timea++;
	wh[u]=low[u]=timea;
	unnow.push_back(u);
	for(auto x:adj[u]){
		if(vis[x]){
			low[u]=min(low[u],wh[x]);
		}else{
			predfs(x);
			low[u]=min(low[u],low[x]);
			if(low[x]>=wh[u]){
			//	cout<<"wtf: "<<u<<" "<<x<<endl;
				fakeadj[u].push_back(newnode);
				while((long long)fakeadj[newnode].size()==0||fakeadj[newnode].back()!=x){
					fakeadj[newnode].push_back(unnow.back());
					unnow.pop_back();
				}
				newnode++;
			}
		}
	}
	//cout<<"magemishe: "<<u<<" "<<wh[u]<<" "<<low[u]<<endl;
}

void pre(){
	newnode=n+1;
	for(long long i=1;i<=n;i++){
		if(vis[i]==0){
			predfs(i);
		}
	}
	for(long long i=1;i<=n;i++){
		vis[i]=0;
	}
}
long long mainres=0;

void dfssolve(long long u){
	vis[u]=1;
	sz[u]=(u<=n);
	for(auto x:fakeadj[u]){
		dfssolve(x);
		sz[u]+=sz[x];
		if(u>n){
			mainres-=sz[x]*(sz[x]-1)*((long long)fakeadj[u].size());
		}
	}
	if(u>n){
		mainres-=(long long)fakeadj[u].size()*(n-sz[u])*(n-sz[u]-1);
	}
	//cout<<u<<" "<<sz[u]<<" "<<(long long)fakeadj[u].size()<<endl;
}


void solve(){
	mainres=n*(n-1)*(n-2);
	for(long long i=1;i<=n;i++){
		if(vis[i]==0){
			dfssolve(i);
		}
	}
	cout<<mainres<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	vorod();
	pre();
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 15452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 15452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 28872 KB Output is correct
2 Correct 44 ms 30152 KB Output is correct
3 Incorrect 39 ms 29132 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 15448 KB Output is correct
2 Correct 2 ms 15452 KB Output is correct
3 Correct 2 ms 15452 KB Output is correct
4 Correct 2 ms 15452 KB Output is correct
5 Correct 2 ms 15452 KB Output is correct
6 Correct 2 ms 15452 KB Output is correct
7 Correct 2 ms 15452 KB Output is correct
8 Correct 2 ms 15572 KB Output is correct
9 Correct 2 ms 15400 KB Output is correct
10 Incorrect 3 ms 15448 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 24636 KB Output is correct
2 Correct 36 ms 26080 KB Output is correct
3 Correct 39 ms 26096 KB Output is correct
4 Correct 34 ms 25936 KB Output is correct
5 Correct 38 ms 25940 KB Output is correct
6 Correct 47 ms 33992 KB Output is correct
7 Correct 39 ms 31176 KB Output is correct
8 Correct 38 ms 29752 KB Output is correct
9 Correct 51 ms 28624 KB Output is correct
10 Incorrect 39 ms 25864 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 15448 KB Output is correct
2 Correct 2 ms 15452 KB Output is correct
3 Correct 3 ms 15452 KB Output is correct
4 Correct 2 ms 15452 KB Output is correct
5 Correct 2 ms 15452 KB Output is correct
6 Correct 2 ms 15400 KB Output is correct
7 Correct 2 ms 15544 KB Output is correct
8 Correct 2 ms 15452 KB Output is correct
9 Correct 2 ms 15452 KB Output is correct
10 Correct 3 ms 15448 KB Output is correct
11 Correct 3 ms 15452 KB Output is correct
12 Correct 2 ms 15452 KB Output is correct
13 Correct 2 ms 15452 KB Output is correct
14 Correct 3 ms 15452 KB Output is correct
15 Correct 2 ms 15452 KB Output is correct
16 Incorrect 3 ms 15452 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 24668 KB Output is correct
2 Correct 49 ms 26068 KB Output is correct
3 Correct 41 ms 25524 KB Output is correct
4 Correct 41 ms 24400 KB Output is correct
5 Correct 35 ms 23208 KB Output is correct
6 Correct 31 ms 22636 KB Output is correct
7 Correct 32 ms 22360 KB Output is correct
8 Correct 32 ms 21816 KB Output is correct
9 Correct 31 ms 21852 KB Output is correct
10 Correct 31 ms 21588 KB Output is correct
11 Correct 28 ms 21328 KB Output is correct
12 Correct 27 ms 21340 KB Output is correct
13 Correct 26 ms 21340 KB Output is correct
14 Correct 31 ms 23500 KB Output is correct
15 Correct 43 ms 30924 KB Output is correct
16 Correct 45 ms 29140 KB Output is correct
17 Correct 48 ms 29640 KB Output is correct
18 Correct 45 ms 28108 KB Output is correct
19 Incorrect 39 ms 24400 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 15452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 15452 KB Output isn't correct
2 Halted 0 ms 0 KB -