Submission #62748

# Submission time Handle Problem Language Result Execution time Memory
62748 2018-07-30T00:30:14 Z MatheusLealV Paths (BOI18_paths) C++17
100 / 100
922 ms 273176 KB
#include <bits/stdc++.h>
#define N 300010
#define M 70
using namespace std;
typedef long long ll;

int n, m, k, c[N];

ll dp[N][M];

vector<int> grafo[N];

ll solve(int x, int mask)
{
    ll ans = 1LL;

    if(dp[x][mask] != -1) return dp[x][mask];

    for(auto v: grafo[x])
    {
        if(mask & (1<<c[v])) continue;

        ans += solve(v, mask | (1<<c[v]));
    }

    return dp[x][mask] = ans;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);

    cin>>n>>m>>k;

    for(int i = 1; i <= n; i++) cin>>c[i];

    for(int i = 1, a, b; i <= m; i++)
    {
        cin>>a>>b;

        grafo[a].push_back(b);

        grafo[b].push_back(a);
    }

    memset(dp, -1, sizeof dp);

    ll ans = 0;

    for(int i = 1; i <= n; i++) ans += solve(i, 1<<c[i]);

    cout<<ans - n<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 137 ms 171768 KB Output is correct
2 Correct 138 ms 172008 KB Output is correct
3 Correct 170 ms 172008 KB Output is correct
4 Correct 128 ms 172008 KB Output is correct
5 Correct 161 ms 172008 KB Output is correct
6 Correct 164 ms 172008 KB Output is correct
7 Correct 134 ms 172008 KB Output is correct
8 Correct 138 ms 172036 KB Output is correct
9 Correct 142 ms 172080 KB Output is correct
10 Correct 129 ms 172140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 178696 KB Output is correct
2 Correct 210 ms 180836 KB Output is correct
3 Correct 620 ms 191468 KB Output is correct
4 Correct 327 ms 191468 KB Output is correct
5 Correct 358 ms 193084 KB Output is correct
6 Correct 616 ms 200660 KB Output is correct
7 Correct 601 ms 206656 KB Output is correct
8 Correct 549 ms 211880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 171768 KB Output is correct
2 Correct 138 ms 172008 KB Output is correct
3 Correct 170 ms 172008 KB Output is correct
4 Correct 128 ms 172008 KB Output is correct
5 Correct 161 ms 172008 KB Output is correct
6 Correct 164 ms 172008 KB Output is correct
7 Correct 134 ms 172008 KB Output is correct
8 Correct 138 ms 172036 KB Output is correct
9 Correct 142 ms 172080 KB Output is correct
10 Correct 129 ms 172140 KB Output is correct
11 Correct 302 ms 178696 KB Output is correct
12 Correct 210 ms 180836 KB Output is correct
13 Correct 620 ms 191468 KB Output is correct
14 Correct 327 ms 191468 KB Output is correct
15 Correct 358 ms 193084 KB Output is correct
16 Correct 616 ms 200660 KB Output is correct
17 Correct 601 ms 206656 KB Output is correct
18 Correct 549 ms 211880 KB Output is correct
19 Correct 253 ms 211880 KB Output is correct
20 Correct 200 ms 211880 KB Output is correct
21 Correct 556 ms 220784 KB Output is correct
22 Correct 318 ms 220784 KB Output is correct
23 Correct 291 ms 222492 KB Output is correct
24 Correct 439 ms 229948 KB Output is correct
25 Correct 660 ms 236344 KB Output is correct
26 Correct 626 ms 241136 KB Output is correct
27 Correct 225 ms 241136 KB Output is correct
28 Correct 264 ms 241136 KB Output is correct
29 Correct 922 ms 250200 KB Output is correct
30 Correct 698 ms 251212 KB Output is correct
31 Correct 857 ms 255308 KB Output is correct
32 Correct 792 ms 262720 KB Output is correct
33 Correct 150 ms 262720 KB Output is correct
34 Correct 148 ms 262720 KB Output is correct
35 Correct 151 ms 262720 KB Output is correct
36 Correct 171 ms 262720 KB Output is correct
37 Correct 155 ms 262720 KB Output is correct
38 Correct 128 ms 262720 KB Output is correct
39 Correct 168 ms 262720 KB Output is correct
40 Correct 131 ms 262720 KB Output is correct
41 Correct 170 ms 262720 KB Output is correct
42 Correct 131 ms 262720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 127 ms 262720 KB Output is correct
2 Correct 171 ms 262720 KB Output is correct
3 Correct 156 ms 262720 KB Output is correct
4 Correct 311 ms 262720 KB Output is correct
5 Correct 257 ms 262720 KB Output is correct
6 Correct 377 ms 262720 KB Output is correct
7 Correct 199 ms 262720 KB Output is correct
8 Correct 369 ms 264012 KB Output is correct
9 Correct 267 ms 266008 KB Output is correct
10 Correct 305 ms 267228 KB Output is correct
11 Correct 249 ms 267228 KB Output is correct
12 Correct 267 ms 268952 KB Output is correct
13 Correct 280 ms 269120 KB Output is correct
14 Correct 338 ms 271736 KB Output is correct
15 Correct 336 ms 273176 KB Output is correct
16 Correct 152 ms 273176 KB Output is correct
17 Correct 148 ms 273176 KB Output is correct
18 Correct 158 ms 273176 KB Output is correct
19 Correct 156 ms 273176 KB Output is correct
20 Correct 132 ms 273176 KB Output is correct
21 Correct 151 ms 273176 KB Output is correct
22 Correct 171 ms 273176 KB Output is correct
23 Correct 159 ms 273176 KB Output is correct
24 Correct 163 ms 273176 KB Output is correct
25 Correct 161 ms 273176 KB Output is correct