Submission #66597

# Submission time Handle Problem Language Result Execution time Memory
66597 2018-08-11T17:50:47 Z Bruteforceman Paths (BOI18_paths) C++11
100 / 100
726 ms 183732 KB
#include "bits/stdc++.h"
using namespace std;
int k;
vector <int> g[300010];
int col[300010];
long long M[1 << 5][300010];

long long dp(int mask, int node) {
	if(M[mask][node] != -1) return M[mask][node];
	long long ans = 1;
	for(auto i : g[node]) {
		if((mask >> col[i]) & 1) {}
		else {
			ans += dp(mask ^ (1 << col[i]), i);
		}
	}
	return M[mask][node] = ans;
}

int main(int argc, char const *argv[])
{
	int n, m;
	scanf("%d %d %d", &n, &m, &k);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &col[i]);
		--col[i];
	}
	for(int i = 0; i < m; i++) {
		int p, q;
		scanf("%d %d", &p, &q);
		g[p].push_back(q);
		g[q].push_back(p);
	}
	memset(M, -1, sizeof M);
	long long ans = 0;
	for(int i = 1; i <= n; i++) {
		ans += dp(1 << col[i], i);
	}
	printf("%lld\n", ans - n);
	return 0;
}

Compilation message

paths.cpp: In function 'int main(int, const char**)':
paths.cpp:23: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:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &col[i]);
   ~~~~~^~~~~~~~~~~~~~~
paths.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &p, &q);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 69 ms 82552 KB Output is correct
2 Correct 66 ms 82568 KB Output is correct
3 Correct 78 ms 82772 KB Output is correct
4 Correct 67 ms 82772 KB Output is correct
5 Correct 70 ms 82808 KB Output is correct
6 Correct 75 ms 82812 KB Output is correct
7 Correct 79 ms 82816 KB Output is correct
8 Correct 65 ms 82864 KB Output is correct
9 Correct 76 ms 82960 KB Output is correct
10 Correct 72 ms 82960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 206 ms 89344 KB Output is correct
2 Correct 172 ms 91484 KB Output is correct
3 Correct 649 ms 102172 KB Output is correct
4 Correct 278 ms 102172 KB Output is correct
5 Correct 262 ms 103820 KB Output is correct
6 Correct 412 ms 111292 KB Output is correct
7 Correct 534 ms 117404 KB Output is correct
8 Correct 528 ms 122428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 82552 KB Output is correct
2 Correct 66 ms 82568 KB Output is correct
3 Correct 78 ms 82772 KB Output is correct
4 Correct 67 ms 82772 KB Output is correct
5 Correct 70 ms 82808 KB Output is correct
6 Correct 75 ms 82812 KB Output is correct
7 Correct 79 ms 82816 KB Output is correct
8 Correct 65 ms 82864 KB Output is correct
9 Correct 76 ms 82960 KB Output is correct
10 Correct 72 ms 82960 KB Output is correct
11 Correct 206 ms 89344 KB Output is correct
12 Correct 172 ms 91484 KB Output is correct
13 Correct 649 ms 102172 KB Output is correct
14 Correct 278 ms 102172 KB Output is correct
15 Correct 262 ms 103820 KB Output is correct
16 Correct 412 ms 111292 KB Output is correct
17 Correct 534 ms 117404 KB Output is correct
18 Correct 528 ms 122428 KB Output is correct
19 Correct 189 ms 122428 KB Output is correct
20 Correct 171 ms 122428 KB Output is correct
21 Correct 568 ms 131516 KB Output is correct
22 Correct 301 ms 131516 KB Output is correct
23 Correct 275 ms 133120 KB Output is correct
24 Correct 389 ms 140692 KB Output is correct
25 Correct 505 ms 146840 KB Output is correct
26 Correct 490 ms 151972 KB Output is correct
27 Correct 208 ms 151972 KB Output is correct
28 Correct 232 ms 151972 KB Output is correct
29 Correct 622 ms 160972 KB Output is correct
30 Correct 485 ms 162024 KB Output is correct
31 Correct 541 ms 166084 KB Output is correct
32 Correct 726 ms 173464 KB Output is correct
33 Correct 72 ms 173464 KB Output is correct
34 Correct 67 ms 173464 KB Output is correct
35 Correct 69 ms 173464 KB Output is correct
36 Correct 75 ms 173464 KB Output is correct
37 Correct 68 ms 173464 KB Output is correct
38 Correct 73 ms 173464 KB Output is correct
39 Correct 66 ms 173464 KB Output is correct
40 Correct 66 ms 173464 KB Output is correct
41 Correct 66 ms 173464 KB Output is correct
42 Correct 72 ms 173464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 173464 KB Output is correct
2 Correct 114 ms 173464 KB Output is correct
3 Correct 116 ms 173464 KB Output is correct
4 Correct 189 ms 173464 KB Output is correct
5 Correct 161 ms 173464 KB Output is correct
6 Correct 255 ms 173464 KB Output is correct
7 Correct 103 ms 173464 KB Output is correct
8 Correct 208 ms 174652 KB Output is correct
9 Correct 148 ms 176884 KB Output is correct
10 Correct 206 ms 178136 KB Output is correct
11 Correct 178 ms 178136 KB Output is correct
12 Correct 146 ms 179724 KB Output is correct
13 Correct 185 ms 180004 KB Output is correct
14 Correct 276 ms 182464 KB Output is correct
15 Correct 256 ms 183732 KB Output is correct
16 Correct 68 ms 183732 KB Output is correct
17 Correct 66 ms 183732 KB Output is correct
18 Correct 72 ms 183732 KB Output is correct
19 Correct 74 ms 183732 KB Output is correct
20 Correct 69 ms 183732 KB Output is correct
21 Correct 71 ms 183732 KB Output is correct
22 Correct 64 ms 183732 KB Output is correct
23 Correct 66 ms 183732 KB Output is correct
24 Correct 63 ms 183732 KB Output is correct
25 Correct 64 ms 183732 KB Output is correct