답안 #112292

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
112292 2019-05-18T13:04:39 Z figter001 철인 이종 경기 (APIO18_duathlon) C++17
5 / 100
1000 ms 230492 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];
}

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);
	}
	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:85: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:88:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&u,&v);
   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 19 ms 2688 KB Output is correct
10 Correct 317 ms 2688 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 3 ms 2688 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 4 ms 2816 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 3 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 3 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 1 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 4 ms 2688 KB Output is correct
31 Correct 3 ms 2688 KB Output is correct
32 Correct 3 ms 2684 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 3 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 19 ms 2688 KB Output is correct
10 Correct 317 ms 2688 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 3 ms 2688 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 4 ms 2816 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 3 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 3 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 1 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 4 ms 2688 KB Output is correct
31 Correct 3 ms 2688 KB Output is correct
32 Correct 3 ms 2684 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 3 ms 2688 KB Output is correct
36 Runtime error 6 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 5800 KB Output is correct
2 Correct 54 ms 5880 KB Output is correct
3 Execution timed out 1082 ms 230492 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2816 KB Output is correct
3 Correct 5 ms 2816 KB Output is correct
4 Correct 5 ms 2816 KB Output is correct
5 Correct 5 ms 2816 KB Output is correct
6 Correct 5 ms 2816 KB Output is correct
7 Correct 5 ms 2816 KB Output is correct
8 Correct 5 ms 2816 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Runtime error 7 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 9180 KB Output is correct
2 Correct 230 ms 9336 KB Output is correct
3 Correct 242 ms 9296 KB Output is correct
4 Correct 231 ms 9080 KB Output is correct
5 Correct 234 ms 9208 KB Output is correct
6 Incorrect 270 ms 12408 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 5 ms 2776 KB Output is correct
3 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 9092 KB Output is correct
2 Correct 219 ms 9208 KB Output is correct
3 Runtime error 65 ms 11512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 19 ms 2688 KB Output is correct
10 Correct 317 ms 2688 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 3 ms 2688 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 4 ms 2816 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 3 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 3 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 1 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 4 ms 2688 KB Output is correct
31 Correct 3 ms 2688 KB Output is correct
32 Correct 3 ms 2684 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 3 ms 2688 KB Output is correct
36 Runtime error 6 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 19 ms 2688 KB Output is correct
10 Correct 317 ms 2688 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 3 ms 2688 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 4 ms 2816 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 3 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 3 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 1 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 4 ms 2688 KB Output is correct
31 Correct 3 ms 2688 KB Output is correct
32 Correct 3 ms 2684 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 3 ms 2688 KB Output is correct
36 Runtime error 6 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Halted 0 ms 0 KB -