답안 #61400

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

struct union_find {
	int par[MAXN];
	int sz[MAXN];
	union_find() {
		for (int i = 0; i < MAXN; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}

	int find (int x) {
		return x == par[x] ? x : par[x] = find(par[x]);
	}

	void merge (int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) {
			return;
		}
		par[x] = y;
		sz[y] += sz[x];
	}
} uf = union_find();

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);
	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);
		uf.merge(x, y);
	}

	for (int i = 1; i <= N; i++) {
		if (i == uf.find(i)) {
			dfs(i, 0);
		}
	}

	ll ans = 0;
	for (int c = 1; c <= N; c++) {
		int sz = uf.sz[uf.find(c)];
		ans += sqr(sz - 1) - sqr(sz - 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:62: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:65: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 10 ms 6964 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 6964 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 138 ms 16080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 16080 KB Output is correct
2 Correct 6 ms 16080 KB Output is correct
3 Correct 6 ms 16080 KB Output is correct
4 Correct 5 ms 16080 KB Output is correct
5 Correct 8 ms 16080 KB Output is correct
6 Correct 5 ms 16080 KB Output is correct
7 Correct 5 ms 16080 KB Output is correct
8 Correct 6 ms 16080 KB Output is correct
9 Correct 6 ms 16080 KB Output is correct
10 Runtime error 10 ms 16080 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 16080 KB Output is correct
2 Correct 159 ms 16080 KB Output is correct
3 Correct 136 ms 16080 KB Output is correct
4 Correct 171 ms 16080 KB Output is correct
5 Correct 191 ms 16080 KB Output is correct
6 Correct 189 ms 16356 KB Output is correct
7 Correct 142 ms 16356 KB Output is correct
8 Correct 126 ms 16356 KB Output is correct
9 Correct 147 ms 16356 KB Output is correct
10 Runtime error 147 ms 16924 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 16924 KB Output is correct
2 Correct 7 ms 16924 KB Output is correct
3 Runtime error 12 ms 16924 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 16924 KB Output is correct
2 Correct 172 ms 16924 KB Output is correct
3 Runtime error 154 ms 17200 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 6964 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 6964 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -