답안 #61399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61399 2018-07-25T18:43:15 Z kingpig9 철인 이종 경기 (APIO18_duathlon) C++11
0 / 100
165 ms 23160 KB
#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);
}

Compilation message

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);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 5112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 5112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 5396 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5564 KB Output is correct
2 Correct 5 ms 5564 KB Output is correct
3 Correct 6 ms 5564 KB Output is correct
4 Correct 5 ms 5564 KB Output is correct
5 Correct 6 ms 5676 KB Output is correct
6 Correct 6 ms 5676 KB Output is correct
7 Correct 6 ms 5676 KB Output is correct
8 Correct 6 ms 5676 KB Output is correct
9 Correct 6 ms 5776 KB Output is correct
10 Runtime error 8 ms 5776 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 10616 KB Output is correct
2 Correct 111 ms 11868 KB Output is correct
3 Correct 123 ms 12996 KB Output is correct
4 Correct 121 ms 14444 KB Output is correct
5 Correct 110 ms 15632 KB Output is correct
6 Correct 106 ms 19388 KB Output is correct
7 Correct 136 ms 19680 KB Output is correct
8 Correct 165 ms 20476 KB Output is correct
9 Correct 126 ms 21340 KB Output is correct
10 Runtime error 11 ms 21340 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 21340 KB Output is correct
2 Correct 7 ms 21340 KB Output is correct
3 Runtime error 11 ms 21340 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 21944 KB Output is correct
2 Correct 113 ms 23160 KB Output is correct
3 Runtime error 10 ms 23160 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 5112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 5112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -