Submission #927597

# Submission time Handle Problem Language Result Execution time Memory
927597 2024-02-15T07:01:13 Z vjudge1 Paths (BOI18_paths) C++17
100 / 100
252 ms 98384 KB
//Bismillahir-Rahmanir-Rahim

#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,popcnt,avx,avx2")

#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pld pair <long double, long double>
#define ll long long
#define ld long double
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define skip continue
#define bpop(x) (ll)__builtin_popcountll(x)

using namespace std;

const int N = 3e5 + 7;
const int M = 5e3 + 7;
const int maxA = 2e6 + 7;
const int inf = 1e9 + 7;
const ll INF = 2e18 + 7;
const int MOD = 1e9 + 7;
const ld eps = 1e-9;

pii dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define int long long

vector <int> g[N];
int n, m, k, a[N], dp[N][33];
void solve() {
    cin >> n >> m >> k;
    for (int i = 1;i <= n;i++)cin >> a[i], a[i]--;
    for (int i = 1;i <= m;i++) {
        int x, y;
        cin >> x >> y;
        g[x].pb(y), g[y].pb(x);
    }
    int ans = 0;
    for (int i = 1;i <= n;i++)dp[i][(1ll << a[i])]++;
    for (int mask = 0;mask < (1ll << k);mask++) {
        for (int v = 1;v <= n;v++) {
            if (dp[v][mask]) {
                for (auto to : g[v]) {
                    if (mask & (1ll << a[to]))skip;
                    dp[to][mask + (1ll << a[to])] += dp[v][mask];
                }
            }
        }
        for (int i = 1;i <= n;i++)ans += dp[i][mask];
    }
    cout << ans - n;
}
signed main() {
    //srand(time(NULL));
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    //freopen("tests.in", "r", stdin);
    //freopen("milkorder.out", "w", stdout);
    int test = 1;
    //cin >> test;
    for (int t = 1;t <= test;t++) {
        //cout << "Case " << t << ": ";
        solve();
    }
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 2 ms 11100 KB Output is correct
3 Correct 2 ms 11100 KB Output is correct
4 Correct 3 ms 11100 KB Output is correct
5 Correct 2 ms 11096 KB Output is correct
6 Correct 2 ms 11096 KB Output is correct
7 Correct 3 ms 11096 KB Output is correct
8 Correct 2 ms 11100 KB Output is correct
9 Correct 3 ms 11100 KB Output is correct
10 Correct 2 ms 11308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 20664 KB Output is correct
2 Correct 44 ms 20560 KB Output is correct
3 Correct 247 ms 97852 KB Output is correct
4 Correct 77 ms 27748 KB Output is correct
5 Correct 70 ms 27644 KB Output is correct
6 Correct 159 ms 73408 KB Output is correct
7 Correct 243 ms 97812 KB Output is correct
8 Correct 245 ms 98256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 2 ms 11100 KB Output is correct
3 Correct 2 ms 11100 KB Output is correct
4 Correct 3 ms 11100 KB Output is correct
5 Correct 2 ms 11096 KB Output is correct
6 Correct 2 ms 11096 KB Output is correct
7 Correct 3 ms 11096 KB Output is correct
8 Correct 2 ms 11100 KB Output is correct
9 Correct 3 ms 11100 KB Output is correct
10 Correct 2 ms 11308 KB Output is correct
11 Correct 55 ms 20664 KB Output is correct
12 Correct 44 ms 20560 KB Output is correct
13 Correct 247 ms 97852 KB Output is correct
14 Correct 77 ms 27748 KB Output is correct
15 Correct 70 ms 27644 KB Output is correct
16 Correct 159 ms 73408 KB Output is correct
17 Correct 243 ms 97812 KB Output is correct
18 Correct 245 ms 98256 KB Output is correct
19 Correct 52 ms 20560 KB Output is correct
20 Correct 46 ms 20420 KB Output is correct
21 Correct 218 ms 97840 KB Output is correct
22 Correct 72 ms 27728 KB Output is correct
23 Correct 67 ms 27728 KB Output is correct
24 Correct 158 ms 73596 KB Output is correct
25 Correct 193 ms 97744 KB Output is correct
26 Correct 191 ms 98384 KB Output is correct
27 Correct 55 ms 20380 KB Output is correct
28 Correct 76 ms 21840 KB Output is correct
29 Correct 252 ms 97856 KB Output is correct
30 Correct 170 ms 59076 KB Output is correct
31 Correct 190 ms 59216 KB Output is correct
32 Correct 248 ms 97876 KB Output is correct
33 Correct 2 ms 11100 KB Output is correct
34 Correct 2 ms 11100 KB Output is correct
35 Correct 2 ms 11100 KB Output is correct
36 Correct 2 ms 11100 KB Output is correct
37 Correct 2 ms 11100 KB Output is correct
38 Correct 3 ms 11368 KB Output is correct
39 Correct 2 ms 11100 KB Output is correct
40 Correct 2 ms 11100 KB Output is correct
41 Correct 2 ms 11100 KB Output is correct
42 Correct 2 ms 11100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11096 KB Output is correct
2 Correct 26 ms 13404 KB Output is correct
3 Correct 17 ms 13404 KB Output is correct
4 Correct 50 ms 41556 KB Output is correct
5 Correct 43 ms 41960 KB Output is correct
6 Correct 84 ms 41628 KB Output is correct
7 Correct 20 ms 13404 KB Output is correct
8 Correct 64 ms 41556 KB Output is correct
9 Correct 55 ms 41928 KB Output is correct
10 Correct 56 ms 41656 KB Output is correct
11 Correct 49 ms 28360 KB Output is correct
12 Correct 50 ms 34884 KB Output is correct
13 Correct 51 ms 28484 KB Output is correct
14 Correct 89 ms 41552 KB Output is correct
15 Correct 73 ms 41556 KB Output is correct
16 Correct 2 ms 11096 KB Output is correct
17 Correct 2 ms 11100 KB Output is correct
18 Correct 2 ms 11100 KB Output is correct
19 Correct 2 ms 11100 KB Output is correct
20 Correct 2 ms 11100 KB Output is correct
21 Correct 2 ms 11100 KB Output is correct
22 Correct 5 ms 11256 KB Output is correct
23 Correct 2 ms 11100 KB Output is correct
24 Correct 3 ms 11100 KB Output is correct
25 Correct 2 ms 11100 KB Output is correct