답안 #63178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63178 2018-08-01T04:04:32 Z 윤교준(#1834) Paths (BOI18_paths) C++11
70 / 100
857 ms 42084 KB
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define befv(V) ((V)[(sz(V)-2)])
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void fg(vector<int> G[], int a, int b) { G[a].eb(b); G[b].eb(a); }

namespace kis2 {
	int *A, *B, *C;

	int N, M;
	int Ans;

	int run(int _N, int _M, int _A[], int _B[], int _C[]) {
		N = _N; M = _M; A = _A; B = _B; C = _C;

		for(int i = 1; i <= M; i++)
			if(C[A[i]] != C[B[i]])
				Ans++;
		return Ans<<1;
	}
}

namespace kis3 {
	static const int MAXN = 300005;

	vector<int> G[MAXN];

	int *A, *B, *C;

	int N, M;
	ll Ans;

	ll run(int _N, int _M, int _A[], int _B[], int _C[]) {
		N = _N; M = _M; A = _A; B = _B; C = _C;

		for(int i = 1; i <= M; i++)
			fg(G, A[i], B[i]);

		Ans = kis2::run(N, M, A, B, C);

		for(int i = 1; i <= N; i++) {
			int cnt[6] = {0, };
			for(int v : G[i]) {
				cnt[C[v]]++;
			}
			for(int a = 1; a <= 5; a++) for(int b = a+1; b <= 5; b++) {
				if(a == C[i] || b == C[i]) continue;
				Ans += ll(cnt[a]) * cnt[b] * 2;
			}
		}

		return Ans;
	}
}

namespace kis4 {
	static const int MAXN = 300005;

	vector<int> G[MAXN];
	int D[MAXN][6];

	int *A, *B, *C;

	int N, M;
	ll Ans;

	ll run(int _N, int _M, int _A[], int _B[], int _C[]) {
		N = _N; M = _M; A = _A; B = _B; C = _C;
		Ans = kis3::run(N, M, A, B, C);

		for(int i = 1; i <= M; i++) fg(G, A[i], B[i]);
		for(int i = 1; i <= N; i++) for(int v : G[i]) D[i][C[v]]++;

		for(int i = 1, a, b; i <= M; i++) {
			a = A[i]; b = B[i];
			if(C[a] == C[b]) continue;
			D[a][C[b]]--; D[b][C[a]]--;

			for(int ca = 1; ca <= 5; ca++) for(int cb = ca+1; cb <= 5; cb++) {
				if(ca == C[a] || cb == C[a] || ca == C[b] || cb == C[b]) continue;
				Ans += ll(D[a][ca]) * D[b][cb] * 2;
				Ans += ll(D[b][ca]) * D[a][cb] * 2;
			}

			D[a][C[b]]++; D[b][C[a]]++;
		}

		return Ans;
	}
}

int A[300005], B[300005];
int C[300005];
int N, M, K;

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> M >> K;
	for(int i = 1; i <= N; i++) cin >> C[i];
	for(int i = 1; i <= M; i++) cin >> A[i] >> B[i];

	if(1 == K) puts("0");
	else if(2 == K) printf("%d\n", kis2::run(N, M, A, B, C));
	else if(3 == K) printf("%lld\n", kis3::run(N, M, A, B, C));
	else if(4 == K) printf("%lld\n", kis4::run(N, M, A, B, C));

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 14456 KB Output is correct
2 Correct 20 ms 14532 KB Output is correct
3 Correct 20 ms 14532 KB Output is correct
4 Correct 21 ms 14632 KB Output is correct
5 Correct 19 ms 14632 KB Output is correct
6 Correct 18 ms 14632 KB Output is correct
7 Correct 20 ms 14632 KB Output is correct
8 Correct 17 ms 14632 KB Output is correct
9 Correct 18 ms 14632 KB Output is correct
10 Correct 20 ms 14632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 20732 KB Output is correct
2 Correct 109 ms 20732 KB Output is correct
3 Correct 512 ms 26752 KB Output is correct
4 Correct 132 ms 26752 KB Output is correct
5 Correct 110 ms 26752 KB Output is correct
6 Correct 389 ms 26752 KB Output is correct
7 Correct 479 ms 26752 KB Output is correct
8 Correct 490 ms 27392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 14456 KB Output is correct
2 Correct 20 ms 14532 KB Output is correct
3 Correct 20 ms 14532 KB Output is correct
4 Correct 21 ms 14632 KB Output is correct
5 Correct 19 ms 14632 KB Output is correct
6 Correct 18 ms 14632 KB Output is correct
7 Correct 20 ms 14632 KB Output is correct
8 Correct 17 ms 14632 KB Output is correct
9 Correct 18 ms 14632 KB Output is correct
10 Correct 20 ms 14632 KB Output is correct
11 Correct 147 ms 20732 KB Output is correct
12 Correct 109 ms 20732 KB Output is correct
13 Correct 512 ms 26752 KB Output is correct
14 Correct 132 ms 26752 KB Output is correct
15 Correct 110 ms 26752 KB Output is correct
16 Correct 389 ms 26752 KB Output is correct
17 Correct 479 ms 26752 KB Output is correct
18 Correct 490 ms 27392 KB Output is correct
19 Correct 136 ms 27392 KB Output is correct
20 Correct 119 ms 27392 KB Output is correct
21 Correct 510 ms 27392 KB Output is correct
22 Correct 123 ms 27392 KB Output is correct
23 Correct 135 ms 27392 KB Output is correct
24 Correct 354 ms 27392 KB Output is correct
25 Correct 510 ms 27392 KB Output is correct
26 Correct 490 ms 27392 KB Output is correct
27 Correct 166 ms 27392 KB Output is correct
28 Correct 201 ms 27392 KB Output is correct
29 Correct 857 ms 42084 KB Output is correct
30 Correct 544 ms 42084 KB Output is correct
31 Correct 548 ms 42084 KB Output is correct
32 Correct 826 ms 42084 KB Output is correct
33 Correct 18 ms 42084 KB Output is correct
34 Correct 19 ms 42084 KB Output is correct
35 Correct 18 ms 42084 KB Output is correct
36 Correct 20 ms 42084 KB Output is correct
37 Correct 19 ms 42084 KB Output is correct
38 Correct 18 ms 42084 KB Output is correct
39 Correct 19 ms 42084 KB Output is correct
40 Correct 17 ms 42084 KB Output is correct
41 Correct 19 ms 42084 KB Output is correct
42 Correct 19 ms 42084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 42084 KB Output isn't correct
2 Halted 0 ms 0 KB -