Submission #112293

# Submission time Handle Problem Language Result Execution time Memory
112293 2019-05-18T13:14:24 Z figter001 Duathlon (APIO18_duathlon) C++17
0 / 100
81 ms 14072 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int nax = 1e5 + 10;

vector<int> g[nax];
int seg[4*nax],lazy[4*nax],fr[nax],to[nax],id[nax];
int T,n,m;
ll ans;

void pro(int n,int s,int e){
	seg[n] += lazy[n]*(e-s+1);
	if(s != e){
		lazy[n*2] += lazy[n];
		lazy[n*2+1] += lazy[n];
	}
	lazy[n] = 0;
}

void update(int n,int s,int e,int l,int r,int val){
	pro(n,s,e);
	if(s > r || e < l)
		return;
	if(s >= l && e <= r){
		lazy[n] += val;
		pro(n,s,e);
		return;
	}
	update(n*2,s,(s+e)/2,l,r,val);
	update(n*2+1,(s+e)/2+1,e,l,r,val);
	seg[n] = seg[n*2] + seg[n*2+1];
}

void dfs(int u,int p,int d){
	id[u] = fr[u] = ++T;

	update(1,1,n,T,T,d);

	for(int v : g[u]){
		if(v == p)
			continue;
		dfs(v,u,d+1);
	}

	to[u] = T;
}

void calc(int u,int p){
	ans += seg[1] - n + 1;
	for(int v : g[u]){
		if(v == p)
			continue;
		update(1,1,n,1,n,1);
		update(1,1,n,fr[v],to[v],-2);

		calc(v,u);

		update(1,1,n,1,n,-1);
		update(1,1,n,fr[v],to[v],2);
	}

}

const int kax = 100;

bool can[kax],vis[kax];

int count(int u,int t){
	if(u == t)return 1;
	vis[u] = 1;
	for(int v : g[u]){
		if(vis[v])continue;
		// cout << v << ' ' << u << endl;
		can[u] |= count(v,t);
	}
	vis[u] = 0;
	return can[u];
}

void go(int u){
	vis[u] = 1;
	for(int v : g[u]){
		if(vis[v])continue;
		go(v);
	}
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}

	go(1);
	for(int i=1;i<=n;i++){
		assert(vis[i]);
	}
	memset(vis,0,sizeof(vis));
	if(n <= 10){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(i == j)continue;
				memset(can,0,sizeof(can));
				// cout << i << ' ' << j << endl;
				count(i,j);
				// cout << i << ' ' << j << endl;
				for(int x=1;x<=n;x++){
					if(x == i || x == j)continue;
					// if(can[x])cout << i << ' ' << x << ' ' << j << endl;
					ans += can[x];
				}
			}
		}
	}else if(n == m){
		ans = n * 1ll * (n-1) * (n-2);
	}else{
		assert(n == m+1);
		dfs(1,0,0);
		calc(1,0);
	}

	printf("%lld\n", ans);
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:93:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
count_triplets.cpp:96:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&u,&v);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 79 ms 14072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 81 ms 11896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 75 ms 11868 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -