Submission #118562

# Submission time Handle Problem Language Result Execution time Memory
118562 2019-06-19T08:20:36 Z DystoriaX Paths (BOI18_paths) C++14
100 / 100
839 ms 97528 KB
#include <bits/stdc++.h>
using namespace std;

int n, m, k;
int col[300010];
vector<int> adj[300010];
long long dp[300010][1 << 5], ans;

int main() {
	scanf("%d%d%d", &n, &m, &k);
	
	for(int i = 1; i <= n; i++) scanf("%d", &col[i]), col[i]--;
	
	while(m--){
		int u, v;
		
		scanf("%d%d", &u, &v);
		
		adj[u].emplace_back(v);
		adj[v].emplace_back(u);
	}
	
	for(int i = 1; i <= n; i++) dp[i][1 << col[i]] = 1;
	
	for(int len = 2; len <= k; len++){
		for(int i = 1; i <= n; i++){
			for(int mask = 0; mask < (1 << k); mask++){
				if(__builtin_popcount(mask) != len - 1) continue;
				
				for(auto v : adj[i]){
					if(!(mask & (1 << col[v]))){
						dp[v][mask | (1 << col[v])] += dp[i][mask];
					}
				}
			}
		}
	}
	
	for(int i = 1; i <= n; i++)
	    for(int mask = 0; mask < (1 << k); mask++)
	        if(__builtin_popcount(mask) > 1) ans += dp[i][mask];
	
	printf("%lld\n", ans);
	
	return 0;
}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &m, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
paths.cpp:12:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%d", &col[i]), col[i]--;
                              ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
paths.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 8 ms 7424 KB Output is correct
6 Correct 8 ms 7424 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 8 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 8 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 15184 KB Output is correct
2 Correct 90 ms 13408 KB Output is correct
3 Correct 559 ms 96760 KB Output is correct
4 Correct 151 ms 22776 KB Output is correct
5 Correct 149 ms 22776 KB Output is correct
6 Correct 420 ms 69496 KB Output is correct
7 Correct 545 ms 96632 KB Output is correct
8 Correct 563 ms 97272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 8 ms 7424 KB Output is correct
6 Correct 8 ms 7424 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 8 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 8 ms 7424 KB Output is correct
11 Correct 111 ms 15184 KB Output is correct
12 Correct 90 ms 13408 KB Output is correct
13 Correct 559 ms 96760 KB Output is correct
14 Correct 151 ms 22776 KB Output is correct
15 Correct 149 ms 22776 KB Output is correct
16 Correct 420 ms 69496 KB Output is correct
17 Correct 545 ms 96632 KB Output is correct
18 Correct 563 ms 97272 KB Output is correct
19 Correct 110 ms 15216 KB Output is correct
20 Correct 92 ms 13452 KB Output is correct
21 Correct 595 ms 96684 KB Output is correct
22 Correct 194 ms 22876 KB Output is correct
23 Correct 139 ms 22780 KB Output is correct
24 Correct 391 ms 69484 KB Output is correct
25 Correct 579 ms 96604 KB Output is correct
26 Correct 563 ms 97528 KB Output is correct
27 Correct 114 ms 13304 KB Output is correct
28 Correct 148 ms 16760 KB Output is correct
29 Correct 814 ms 96632 KB Output is correct
30 Correct 510 ms 55660 KB Output is correct
31 Correct 522 ms 55512 KB Output is correct
32 Correct 839 ms 96656 KB Output is correct
33 Correct 9 ms 7424 KB Output is correct
34 Correct 9 ms 7424 KB Output is correct
35 Correct 8 ms 7424 KB Output is correct
36 Correct 8 ms 7424 KB Output is correct
37 Correct 8 ms 7424 KB Output is correct
38 Correct 9 ms 7424 KB Output is correct
39 Correct 8 ms 7424 KB Output is correct
40 Correct 9 ms 7424 KB Output is correct
41 Correct 8 ms 7424 KB Output is correct
42 Correct 8 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 61 ms 9376 KB Output is correct
3 Correct 35 ms 9344 KB Output is correct
4 Correct 154 ms 37112 KB Output is correct
5 Correct 127 ms 37860 KB Output is correct
6 Correct 378 ms 37112 KB Output is correct
7 Correct 42 ms 9340 KB Output is correct
8 Correct 221 ms 37084 KB Output is correct
9 Correct 172 ms 37872 KB Output is correct
10 Correct 223 ms 37716 KB Output is correct
11 Correct 191 ms 23112 KB Output is correct
12 Correct 210 ms 30668 KB Output is correct
13 Correct 195 ms 23152 KB Output is correct
14 Correct 362 ms 36984 KB Output is correct
15 Correct 367 ms 36984 KB Output is correct
16 Correct 8 ms 7464 KB Output is correct
17 Correct 8 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 8 ms 7424 KB Output is correct
20 Correct 8 ms 7424 KB Output is correct
21 Correct 8 ms 7424 KB Output is correct
22 Correct 8 ms 7424 KB Output is correct
23 Correct 9 ms 7424 KB Output is correct
24 Correct 9 ms 7424 KB Output is correct
25 Correct 8 ms 7424 KB Output is correct