답안 #386657

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386657 2021-04-07T07:33:20 Z maximath_1 Paths (BOI18_paths) C++11
100 / 100
585 ms 116076 KB
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <numeric>
#include <iostream>
#include <queue>
#include <assert.h>
#include <map>
#include <set>
#include <limits.h>
#include <random>
#include <chrono>
using namespace std;
 
#define ll long long
#define ld long double
const int MX = 300005;
const int BLOCK = 105;
const ll inf = 8000000000000000069ll;
const ll mod = 1e9 + 7;
const ll inv2 = (mod + 1) / 2;
const int dxh[] = {1, 1, -1, -1, 2, 2, -2, -2};
const int dyh[] = {2, -2, 2, -2, 1, -1, 1, -1}; // horse
const int dx[] = {1, -1, 0, 0, 0, 0};
const int dy[] = {0, 0, 1, -1, 0, 0}; // adj
const int dz[] = {0, 0, 0, 0, 1, -1};
const int dxd[] = {1, 1, 1, 0, -1, -1, -1, 0};
const int dyd[] = {1, 0, -1, -1, -1, 0, 1, 1}; // diag

int n, m, k, col[MX];
vector<int> adj[MX];
ll dp[MX][40];

int main(){
	cin.tie(0) -> sync_with_stdio(0);

	cin >> n >> m >> k;
	for(int i = 1; i <= n; i ++) cin >> col[i];
	for(int u, v, i = 0; i < m; i ++){
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	ll ans = 0ll;

	for(int msk = 1; msk < (1 << k); msk ++){
		for(int i = 1; i <= n; i ++){
			dp[i][msk] = 0;
			if((msk & (1 << (col[i] - 1))) == 0) continue;
			if(msk - (1 << (col[i] - 1)) == 0) dp[i][msk] = 1;
			for(int nx : adj[i])
				dp[i][msk] += dp[nx][msk - (1 << (col[i] - 1))];

			ans += dp[i][msk];
		}
	}

	ans -= n;

	cout << ans << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7404 KB Output is correct
2 Correct 6 ms 7404 KB Output is correct
3 Correct 7 ms 7404 KB Output is correct
4 Correct 6 ms 7532 KB Output is correct
5 Correct 6 ms 7404 KB Output is correct
6 Correct 7 ms 7404 KB Output is correct
7 Correct 6 ms 7404 KB Output is correct
8 Correct 6 ms 7404 KB Output is correct
9 Correct 6 ms 7404 KB Output is correct
10 Correct 6 ms 7420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 15468 KB Output is correct
2 Correct 63 ms 13548 KB Output is correct
3 Correct 430 ms 115436 KB Output is correct
4 Correct 137 ms 24684 KB Output is correct
5 Correct 138 ms 24812 KB Output is correct
6 Correct 276 ms 82016 KB Output is correct
7 Correct 415 ms 115436 KB Output is correct
8 Correct 427 ms 116076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7404 KB Output is correct
2 Correct 6 ms 7404 KB Output is correct
3 Correct 7 ms 7404 KB Output is correct
4 Correct 6 ms 7532 KB Output is correct
5 Correct 6 ms 7404 KB Output is correct
6 Correct 7 ms 7404 KB Output is correct
7 Correct 6 ms 7404 KB Output is correct
8 Correct 6 ms 7404 KB Output is correct
9 Correct 6 ms 7404 KB Output is correct
10 Correct 6 ms 7420 KB Output is correct
11 Correct 79 ms 15468 KB Output is correct
12 Correct 63 ms 13548 KB Output is correct
13 Correct 430 ms 115436 KB Output is correct
14 Correct 137 ms 24684 KB Output is correct
15 Correct 138 ms 24812 KB Output is correct
16 Correct 276 ms 82016 KB Output is correct
17 Correct 415 ms 115436 KB Output is correct
18 Correct 427 ms 116076 KB Output is correct
19 Correct 81 ms 15468 KB Output is correct
20 Correct 80 ms 13548 KB Output is correct
21 Correct 409 ms 115436 KB Output is correct
22 Correct 160 ms 24756 KB Output is correct
23 Correct 124 ms 24684 KB Output is correct
24 Correct 274 ms 82144 KB Output is correct
25 Correct 407 ms 115436 KB Output is correct
26 Correct 407 ms 115972 KB Output is correct
27 Correct 67 ms 13548 KB Output is correct
28 Correct 104 ms 17260 KB Output is correct
29 Correct 547 ms 115404 KB Output is correct
30 Correct 327 ms 64864 KB Output is correct
31 Correct 334 ms 64872 KB Output is correct
32 Correct 585 ms 115564 KB Output is correct
33 Correct 5 ms 7404 KB Output is correct
34 Correct 6 ms 7404 KB Output is correct
35 Correct 6 ms 7404 KB Output is correct
36 Correct 6 ms 7404 KB Output is correct
37 Correct 7 ms 7404 KB Output is correct
38 Correct 7 ms 7404 KB Output is correct
39 Correct 6 ms 7404 KB Output is correct
40 Correct 6 ms 7404 KB Output is correct
41 Correct 6 ms 7404 KB Output is correct
42 Correct 6 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7404 KB Output is correct
2 Correct 27 ms 9452 KB Output is correct
3 Correct 29 ms 9452 KB Output is correct
4 Correct 121 ms 43244 KB Output is correct
5 Correct 84 ms 44004 KB Output is correct
6 Correct 219 ms 43244 KB Output is correct
7 Correct 25 ms 9452 KB Output is correct
8 Correct 151 ms 43372 KB Output is correct
9 Correct 110 ms 44004 KB Output is correct
10 Correct 134 ms 43876 KB Output is correct
11 Correct 114 ms 26216 KB Output is correct
12 Correct 127 ms 35320 KB Output is correct
13 Correct 114 ms 26468 KB Output is correct
14 Correct 228 ms 43244 KB Output is correct
15 Correct 248 ms 43500 KB Output is correct
16 Correct 6 ms 7532 KB Output is correct
17 Correct 5 ms 7404 KB Output is correct
18 Correct 6 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 6 ms 7404 KB Output is correct
21 Correct 6 ms 7404 KB Output is correct
22 Correct 5 ms 7404 KB Output is correct
23 Correct 5 ms 7404 KB Output is correct
24 Correct 6 ms 7404 KB Output is correct
25 Correct 7 ms 7404 KB Output is correct