제출 #408028

#제출 시각아이디문제언어결과실행 시간메모리
408028juggernaut철인 이종 경기 (APIO18_duathlon)C++17
23 / 100
1122 ms1048580 KiB
#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);
}

컴파일 시 표준 에러 (stderr) 메시지

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);
      |   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...