Submission #522511

# Submission time Handle Problem Language Result Execution time Memory
522511 2022-02-05T05:45:18 Z Leonardo_Paes Paths (BOI18_paths) C++17
70 / 100
328 ms 58128 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 3e5+10, maxl = 1<<5 - 1;

int c[maxn];
vector<int> grafo[maxn];

long long dp[maxn][maxl];

long long solve(int u, int mask){
	if(dp[u][mask] != -1) return dp[u][mask];
	long long tot = 1;
	for(int v : grafo[u]) if(!(mask&c[v])) tot += solve(v, mask^c[v]);
	return dp[u][mask] = tot;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n, m, k;
	cin >> n >> m >> k;
	for(int i=1; i<=n; i++){
		cin >> c[i];
		c[i] = (1<<(c[i]-1));
	}
	for(int i=1; i<=m; i++){
		int u, v;
		cin >> u >> v;
		grafo[u].push_back(v);
		grafo[v].push_back(u);
	}
	long long ans = 0;
	memset(dp, -1, sizeof dp);
	for(int i=1; i<=n; i++) ans += solve(i, c[i]);
	cout << ans - n << "\n";
	return 0;
}

Compilation message

paths.cpp:4:38: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
    4 | const int maxn = 3e5+10, maxl = 1<<5 - 1;
      |                                    ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 44876 KB Output is correct
2 Correct 24 ms 44912 KB Output is correct
3 Correct 19 ms 44876 KB Output is correct
4 Correct 23 ms 44896 KB Output is correct
5 Correct 18 ms 44876 KB Output is correct
6 Correct 19 ms 44880 KB Output is correct
7 Correct 19 ms 44876 KB Output is correct
8 Correct 18 ms 44880 KB Output is correct
9 Correct 18 ms 44876 KB Output is correct
10 Correct 19 ms 44836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 48508 KB Output is correct
2 Correct 68 ms 48488 KB Output is correct
3 Correct 277 ms 57152 KB Output is correct
4 Correct 146 ms 52476 KB Output is correct
5 Correct 93 ms 52524 KB Output is correct
6 Correct 186 ms 55812 KB Output is correct
7 Correct 288 ms 57504 KB Output is correct
8 Correct 283 ms 58116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 44876 KB Output is correct
2 Correct 24 ms 44912 KB Output is correct
3 Correct 19 ms 44876 KB Output is correct
4 Correct 23 ms 44896 KB Output is correct
5 Correct 18 ms 44876 KB Output is correct
6 Correct 19 ms 44880 KB Output is correct
7 Correct 19 ms 44876 KB Output is correct
8 Correct 18 ms 44880 KB Output is correct
9 Correct 18 ms 44876 KB Output is correct
10 Correct 19 ms 44836 KB Output is correct
11 Correct 89 ms 48508 KB Output is correct
12 Correct 68 ms 48488 KB Output is correct
13 Correct 277 ms 57152 KB Output is correct
14 Correct 146 ms 52476 KB Output is correct
15 Correct 93 ms 52524 KB Output is correct
16 Correct 186 ms 55812 KB Output is correct
17 Correct 288 ms 57504 KB Output is correct
18 Correct 283 ms 58116 KB Output is correct
19 Correct 88 ms 51312 KB Output is correct
20 Correct 67 ms 50704 KB Output is correct
21 Correct 289 ms 57548 KB Output is correct
22 Correct 105 ms 52444 KB Output is correct
23 Correct 101 ms 52512 KB Output is correct
24 Correct 199 ms 55920 KB Output is correct
25 Correct 319 ms 57408 KB Output is correct
26 Correct 251 ms 58128 KB Output is correct
27 Correct 84 ms 50780 KB Output is correct
28 Correct 108 ms 52176 KB Output is correct
29 Correct 328 ms 57284 KB Output is correct
30 Correct 274 ms 54208 KB Output is correct
31 Correct 290 ms 54324 KB Output is correct
32 Correct 294 ms 57352 KB Output is correct
33 Correct 19 ms 44864 KB Output is correct
34 Correct 18 ms 44872 KB Output is correct
35 Correct 17 ms 44868 KB Output is correct
36 Correct 18 ms 44876 KB Output is correct
37 Correct 20 ms 44996 KB Output is correct
38 Correct 23 ms 44836 KB Output is correct
39 Correct 19 ms 44868 KB Output is correct
40 Correct 25 ms 44872 KB Output is correct
41 Correct 18 ms 44916 KB Output is correct
42 Correct 18 ms 44940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 44932 KB Output is correct
2 Incorrect 42 ms 46020 KB Output isn't correct
3 Halted 0 ms 0 KB -