답안 #226974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
226974 2020-04-25T19:09:32 Z anubhavdhar Paths (BOI18_paths) C++14
100 / 100
576 ms 55800 KB
#include<bits/stdc++.h>

#define ll long long int
#define pb push_back
#define mp make_pair
#define FOR(i,n) for(i=0;i<(n);++i)
#define FORe(i,n) for(i=1;i<=(n);++i)
#define FORr(i,a,b) for(i=(a);i<(b);++i)
#define FORrev(i,n) for(i=(n);i>=0;--i)
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define ff first 
#define ss second
#define cd complex<double>
#define vcd vector<cd>
#define ldd long double
#define all(x) (x).begin(),(x).end()

using namespace std;

const short int __PRECISION = 10;

const ll MOD = 1e9+7;
const ll INF = 1e17 + 1101;
const ll LOGN = 17;
const ll MAXN = 2e5+5;
const ll ROOTN = 320;

const ldd PI = acos(-1);
const ldd EPS = 1e-7;

int main()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	


	int N,M,K;
	int i,j,k,mask;
	ll ans = 0;

	cin>>N>>M>>K;

	vi g[N+1];
	ll dp[N+1][(1<<K)],col[N+1];

	for(i = 1; i <= N; ++i)
	{
		cin>>j;
		col[i] = j-1;
	}

	for(i = 0; i < M; ++i)
	{
		cin>>j>>k;
		if(col[j] != col[k])
		{
			g[j].pb(k);
			g[k].pb(j);
		}
	}

	for(i = 0; i <= N; ++i)
		for(mask = 0; mask < (1<<K); ++mask)
			dp[i][mask] = 0;

	for(i = 1; i <= N; ++i)
		dp[i][(1<<col[i])] = 1;
	
	for(mask = 0; mask < (1<<K); ++mask)
		for(i = 1; i <= N; ++i)
			if(mask&(1<<col[i]))
				for(ll b : g[i])
					if(((1<<col[b])&(mask)) == 0)
						dp[b][(mask | (1<<col[b]))] +=	dp[i][mask];

	for(i = 1; i <= N; ++i)
		for(mask = 0; mask < (1<<K); ++mask)
			if(__builtin_popcount(mask) > 1)
				ans += dp[i][mask];

	cout<<ans;
	return 0;
}   
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 6264 KB Output is correct
2 Correct 66 ms 4256 KB Output is correct
3 Correct 372 ms 36344 KB Output is correct
4 Correct 117 ms 6392 KB Output is correct
5 Correct 63 ms 1784 KB Output is correct
6 Correct 307 ms 25704 KB Output is correct
7 Correct 414 ms 36344 KB Output is correct
8 Correct 430 ms 36856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 84 ms 6264 KB Output is correct
12 Correct 66 ms 4256 KB Output is correct
13 Correct 372 ms 36344 KB Output is correct
14 Correct 117 ms 6392 KB Output is correct
15 Correct 63 ms 1784 KB Output is correct
16 Correct 307 ms 25704 KB Output is correct
17 Correct 414 ms 36344 KB Output is correct
18 Correct 430 ms 36856 KB Output is correct
19 Correct 90 ms 6264 KB Output is correct
20 Correct 71 ms 4380 KB Output is correct
21 Correct 360 ms 36216 KB Output is correct
22 Correct 94 ms 6392 KB Output is correct
23 Correct 63 ms 1784 KB Output is correct
24 Correct 297 ms 25680 KB Output is correct
25 Correct 478 ms 36344 KB Output is correct
26 Correct 358 ms 36728 KB Output is correct
27 Correct 78 ms 7416 KB Output is correct
28 Correct 100 ms 6904 KB Output is correct
29 Correct 576 ms 55624 KB Output is correct
30 Correct 458 ms 30572 KB Output is correct
31 Correct 454 ms 31464 KB Output is correct
32 Correct 566 ms 55800 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 4 ms 384 KB Output is correct
35 Correct 4 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 40 ms 2560 KB Output is correct
3 Correct 25 ms 2432 KB Output is correct
4 Correct 90 ms 12412 KB Output is correct
5 Correct 69 ms 12400 KB Output is correct
6 Correct 211 ms 31480 KB Output is correct
7 Correct 29 ms 2552 KB Output is correct
8 Correct 130 ms 18808 KB Output is correct
9 Correct 124 ms 18924 KB Output is correct
10 Correct 123 ms 19692 KB Output is correct
11 Correct 108 ms 16624 KB Output is correct
12 Correct 128 ms 24552 KB Output is correct
13 Correct 112 ms 16872 KB Output is correct
14 Correct 212 ms 31480 KB Output is correct
15 Correct 289 ms 31480 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct