제출 #61399

#제출 시각아이디문제언어결과실행 시간메모리
61399kingpig9Duathlon (APIO18_duathlon)C++11
0 / 100
165 ms23160 KiB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5 + 10;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))

ll sqr (ll x) {
	return x * x;
}

int N, M;
vector<int> adj[MAXN];
int sub[MAXN];

void dfs (int x, int p) {
	sub[x] = 1;
	if (p) {
		adj[x].erase(find(all(adj[x]), p));
	}

	for (int y : adj[x]) {
		dfs(y, x);
		sub[x] += sub[y];
	}
}

int main() {
	//subtask 5
	scanf("%d %d", &N, &M);
	assert(M == N - 1);
	for (int i = 1; i < N; i++) {
		int x, y;
		scanf("%d %d", &x, &y);
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs(1, 0);

	ll ans = 0;
	for (int c = 1; c <= N; c++) {
		ans += sqr(N - 1) - sqr(N - sub[c]);
		for (int y : adj[c]) {
			ans -= sqr(sub[y]);
		}
	}
	printf("%lld\n", ans);
}

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

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:37: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:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   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...