답안 #408028

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
408028 2021-05-19T05:40:17 Z juggernaut 철인 이종 경기 (APIO18_duathlon) C++17
23 / 100
1000 ms 1048580 KB
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
int n,m;
int sz[100005];
vector<int>g[100005];
void dfs(int v,int p){
	sz[v]=1;
	for(int to:g[v])if(to!=p){
		dfs(to,v);
		sz[v]+=sz[to];
	}
}
int root;
ll ans=0;
void calc(int v,int p){
	ll sum=0;
	vector<int>vec;
	for(int to:g[v])if(to!=p)vec.push_back(sz[to]);
	if(root^v)vec.push_back(sz[root]-sz[v]);
	for(int x:vec)sum+=x;
	for(int x:vec){
		sum-=x;
		ans+=1ll*x*sum;
		sum+=x;
	}
	for(int to:g[v])if(to!=p)calc(to,v);
}
int main(){
	scanf("%d%d",&n,&m);
	while(m--){
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(root=1;root<=n;root++)if(!sz[root])dfs(root,root),calc(root,root);
	printf("%lld",ans);
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
count_triplets.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 641 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 641 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1122 ms 395716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Correct 3 ms 2596 KB Output is correct
4 Correct 3 ms 2764 KB Output is correct
5 Correct 4 ms 2636 KB Output is correct
6 Correct 3 ms 2636 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 3 ms 2688 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 3 ms 2656 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 3 ms 2636 KB Output is correct
16 Correct 4 ms 2636 KB Output is correct
17 Correct 3 ms 2636 KB Output is correct
18 Correct 3 ms 2636 KB Output is correct
19 Correct 4 ms 2660 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 6212 KB Output is correct
2 Correct 107 ms 6292 KB Output is correct
3 Correct 97 ms 6276 KB Output is correct
4 Correct 116 ms 6388 KB Output is correct
5 Correct 79 ms 6380 KB Output is correct
6 Correct 110 ms 14740 KB Output is correct
7 Correct 100 ms 11900 KB Output is correct
8 Correct 109 ms 10436 KB Output is correct
9 Correct 97 ms 9116 KB Output is correct
10 Correct 114 ms 6400 KB Output is correct
11 Correct 103 ms 6384 KB Output is correct
12 Correct 103 ms 6380 KB Output is correct
13 Correct 99 ms 6392 KB Output is correct
14 Correct 90 ms 6312 KB Output is correct
15 Correct 58 ms 6084 KB Output is correct
16 Correct 36 ms 5408 KB Output is correct
17 Correct 48 ms 7392 KB Output is correct
18 Correct 49 ms 7196 KB Output is correct
19 Correct 48 ms 7256 KB Output is correct
20 Correct 60 ms 7152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 4 ms 2636 KB Output is correct
3 Runtime error 723 ms 1048580 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 6364 KB Output is correct
2 Correct 143 ms 6356 KB Output is correct
3 Runtime error 870 ms 1048580 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 641 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 641 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -