Submission #864401

# Submission time Handle Problem Language Result Execution time Memory
864401 2023-10-22T18:00:22 Z iskhakkutbilim Paths (BOI18_paths) C++17
100 / 100
276 ms 95832 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 3e5;
int n, m, col[N+1];
vector<int> g[N+1];
int ans;
int dp[N + 1][1<<5];


main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   int k;
	cin >> n >> m >> k;
	for(int i = 0;i < n; i++){
		cin >> col[i];
		col[i]--;
	}
	for(int i = 0;i < m; i++){
		int a, b; cin >> a >> b;
		a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	for(int i = 0;i < n; i++){
		dp[i][(1<<col[i])] = 1;
	}
	for(int mask = 0; mask < (1<<k); mask++){
		for(int v = 0; v < n; v++){
			if(!dp[v][mask]) continue;
			for(int to : g[v]){
				if(mask & (1<<col[to])) continue;
				dp[to][mask | (1<<col[to])]+= dp[v][mask];
			}
		}
	}
	for(int mask = 0; mask < (1<<k); mask++){
		if(__builtin_popcount(mask) < 2) continue;
		for(int i = 0;i < n; i++){
			ans+= dp[i][mask];
		}
	}
	cout << ans;
	return 0;
}

Compilation message

paths.cpp:15:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   15 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8696 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 18000 KB Output is correct
2 Correct 44 ms 18012 KB Output is correct
3 Correct 171 ms 95388 KB Output is correct
4 Correct 70 ms 27220 KB Output is correct
5 Correct 64 ms 26980 KB Output is correct
6 Correct 145 ms 71228 KB Output is correct
7 Correct 160 ms 95316 KB Output is correct
8 Correct 221 ms 95828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8696 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 64 ms 18000 KB Output is correct
12 Correct 44 ms 18012 KB Output is correct
13 Correct 171 ms 95388 KB Output is correct
14 Correct 70 ms 27220 KB Output is correct
15 Correct 64 ms 26980 KB Output is correct
16 Correct 145 ms 71228 KB Output is correct
17 Correct 160 ms 95316 KB Output is correct
18 Correct 221 ms 95828 KB Output is correct
19 Correct 48 ms 18004 KB Output is correct
20 Correct 43 ms 17904 KB Output is correct
21 Correct 175 ms 95452 KB Output is correct
22 Correct 68 ms 27120 KB Output is correct
23 Correct 59 ms 27044 KB Output is correct
24 Correct 120 ms 70852 KB Output is correct
25 Correct 163 ms 95312 KB Output is correct
26 Correct 162 ms 95832 KB Output is correct
27 Correct 52 ms 17904 KB Output is correct
28 Correct 65 ms 19372 KB Output is correct
29 Correct 276 ms 95504 KB Output is correct
30 Correct 164 ms 58564 KB Output is correct
31 Correct 170 ms 58564 KB Output is correct
32 Correct 236 ms 95416 KB Output is correct
33 Correct 2 ms 8536 KB Output is correct
34 Correct 1 ms 8536 KB Output is correct
35 Correct 1 ms 8540 KB Output is correct
36 Correct 2 ms 8540 KB Output is correct
37 Correct 2 ms 8540 KB Output is correct
38 Correct 2 ms 8540 KB Output is correct
39 Correct 2 ms 8540 KB Output is correct
40 Correct 1 ms 8540 KB Output is correct
41 Correct 2 ms 8540 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 25 ms 10964 KB Output is correct
3 Correct 15 ms 10844 KB Output is correct
4 Correct 47 ms 40964 KB Output is correct
5 Correct 41 ms 41416 KB Output is correct
6 Correct 103 ms 41040 KB Output is correct
7 Correct 18 ms 10840 KB Output is correct
8 Correct 69 ms 41068 KB Output is correct
9 Correct 53 ms 41424 KB Output is correct
10 Correct 59 ms 41160 KB Output is correct
11 Correct 64 ms 27860 KB Output is correct
12 Correct 59 ms 35656 KB Output is correct
13 Correct 50 ms 29004 KB Output is correct
14 Correct 88 ms 42400 KB Output is correct
15 Correct 84 ms 42504 KB Output is correct
16 Correct 2 ms 8536 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8636 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 8540 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct