답안 #864359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864359 2023-10-22T15:31:38 Z maks007 Paths (BOI18_paths) C++14
70 / 100
468 ms 42092 KB
#include "bits/stdc++.h"

using namespace std;

#define int long long

vector <int> color;
vector <vector <int>> cntColor, g, dp;

signed main () {
	int n, m, k;
	cin >> n >> m >> k;
	color.resize(n);
	cntColor.resize(n, vector <int> (k + 1, 0));
	g.resize(n);
	for(int i = 0; i < n; i ++) cin >> color[i];
	for(int i = 0, u, v; i < m; i ++) {
		cin >> u >> v;
		u --, v --;
		g[u].push_back(v);
		g[v].push_back(u);
		cntColor[u][color[v]] ++;
		cntColor[v][color[u]] ++;
	}
	int ans = 0;
	for(int color2 = 1; color2 <= k; color2 ++) {
		for(int i = 0; i < n; i ++) {
			if(color[i] == color2) {
				for(int color1 = 1; color1 <= k; color1 ++) {
					if(color1 == color2) continue;
					ans += cntColor[i][color1];
					if(k == 2) continue;
					for(int color3 = color1 + 1; color3 <= k; color3 ++) {
						if(color3 == color2) continue;
						ans += 2 * (cntColor[i][color1] * cntColor[i][color3]);
					}
				}
			}
		}
  	}
  	if(k >= 4) {
  		for(int v = 0; v < n; v ++) {
  			for(auto u : g[v]) {
  				if(color[u] == color[v]) continue;
  				for(int i = 1; i <= k; i ++) {
  					if(i == color[u] || color[v] == i) continue;
  					for(int j = 1; j <= k; j ++) {
  						if(j == i || j == color[u] || j == color[v]) continue;
  						ans += cntColor[v][i] * cntColor[u][j];
  					}
  				}	
  			}
  		}
  	}
  	if(k >= 5) {
		dp.resize(n, vector <int> (1 << (k + 1)));
  		for(int i = 0; i < n; i ++) {
  			for(int color1 = 1; color1 <= k; color1 ++) {
  				for(int color2 = color1 + 1; color2 <= k; color2 ++) {
  					int cnt = 0;
  					for(auto u : g[i]) {
  						if(color[u] == color1 || color[u] == color2) cnt ++;
  					}
  					dp[i][(1 << color1) ^ (1 << color2)] = cnt;
  				}
  			}
  		}
  		
  		for(int mid = 0; mid < n; mid ++) {
  			for(auto l : g[mid]) {
  				if(color[mid] == color[l]) continue;
  				for(auto r : g[mid]) {
  					if(color[mid] == color[r] || color[l] == color[r]) continue;
  					int bitVal = ((1 << (k + 1)) - 1) ^ (1 << color[mid]) ^ (1 << color[l]) ^ (1 << color[r]);
  					ans += dp[l][bitVal] * dp[r][bitVal];
  				}
  			}
  		}
  	}
  	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 8016 KB Output is correct
2 Correct 88 ms 7400 KB Output is correct
3 Correct 360 ms 41324 KB Output is correct
4 Correct 139 ms 11004 KB Output is correct
5 Correct 164 ms 11104 KB Output is correct
6 Correct 253 ms 29632 KB Output is correct
7 Correct 352 ms 41296 KB Output is correct
8 Correct 332 ms 41960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 110 ms 8016 KB Output is correct
12 Correct 88 ms 7400 KB Output is correct
13 Correct 360 ms 41324 KB Output is correct
14 Correct 139 ms 11004 KB Output is correct
15 Correct 164 ms 11104 KB Output is correct
16 Correct 253 ms 29632 KB Output is correct
17 Correct 352 ms 41296 KB Output is correct
18 Correct 332 ms 41960 KB Output is correct
19 Correct 117 ms 8020 KB Output is correct
20 Correct 101 ms 7400 KB Output is correct
21 Correct 361 ms 41320 KB Output is correct
22 Correct 142 ms 11108 KB Output is correct
23 Correct 155 ms 10972 KB Output is correct
24 Correct 258 ms 29636 KB Output is correct
25 Correct 337 ms 41448 KB Output is correct
26 Correct 365 ms 42092 KB Output is correct
27 Correct 117 ms 7504 KB Output is correct
28 Correct 127 ms 9808 KB Output is correct
29 Correct 427 ms 41448 KB Output is correct
30 Correct 255 ms 24264 KB Output is correct
31 Correct 301 ms 24384 KB Output is correct
32 Correct 468 ms 41448 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 149 ms 2708 KB Output isn't correct
3 Halted 0 ms 0 KB -