Submission #1007748

# Submission time Handle Problem Language Result Execution time Memory
1007748 2024-06-25T12:34:53 Z amirhoseinfar1385 Duathlon (APIO18_duathlon) C++17
Compilation error
0 ms 0 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 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 pre(){
	newnode=n+1;
	for(long long i=1;i<=n;i++){
		if(vis[i]==0){
			predfs(i);
			dfssolve(i);
		}
	}
	for(long long i=1;i<=n;i++){
		vis[i]=0;
	}
}
long long mainres=0;



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();
}

Compilation message

count_triplets.cpp: In function 'void dfssolve(long long int)':
count_triplets.cpp:51:4: error: 'mainres' was not declared in this scope
   51 |    mainres-=sz[x]*(sz[x]-1)*((long long)fakeadj[u].size());
      |    ^~~~~~~
count_triplets.cpp:55:3: error: 'mainres' was not declared in this scope
   55 |   mainres-=(long long)fakeadj[u].size()*(n-sz[u])*(n-sz[u]-1);
      |   ^~~~~~~