Submission #543826

# Submission time Handle Problem Language Result Execution time Memory
543826 2022-03-31T13:32:40 Z Andrei_Calota Paths (BOI18_paths) C++14
100 / 100
832 ms 97100 KB
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;
using LL = long long;
const int NMAX = 3e5;
const int KMAX = 5;

int n, m, k; vector<int> graph[1 + NMAX];
int color[1 + NMAX]; LL dp[1 + NMAX][1 << KMAX];
void read () {
    cin >> n >> m >> k;
    for ( int i = 1; i <= n; i ++ ) {
       cin >> color[i]; color[i] --;
       dp[i][1 << color[i]] = 1;
    }
    for ( int i = 1; i <= m; i ++ ) {
       int u, v; cin >> u >> v;
       graph[u].push_back ( v );
       graph[v].push_back ( u );
    }
}
void compute_dp () {
    for ( int mask = 1; mask < (1 << k); mask ++ )
       for ( int prev = 1; prev <= n; prev ++ )
          for ( auto curr : graph[prev] )
             if ( !( mask & (1 << color[curr]) ) )
               dp[curr][mask + (1 << color[curr])] += dp[prev][mask];
}
int count_bits ( int x ) {
   int answer = 0;
   while ( x ) {
      answer ++;
      x &= (x - 1);
   }
   return answer;
}
void solve () {
    LL answer = 0;
    for ( int mask = 1; mask < (1 << k); mask ++ )
       if ( count_bits ( mask ) > 1 )
         for ( int i = 1; i <= n; i ++ )
              answer += dp[i][mask];
    cout << answer;
}
int main()
{
   read (); compute_dp (); solve ();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7352 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7352 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7352 KB Output is correct
10 Correct 4 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 15072 KB Output is correct
2 Correct 150 ms 13388 KB Output is correct
3 Correct 552 ms 96488 KB Output is correct
4 Correct 203 ms 22720 KB Output is correct
5 Correct 191 ms 22732 KB Output is correct
6 Correct 389 ms 69472 KB Output is correct
7 Correct 542 ms 96500 KB Output is correct
8 Correct 547 ms 97056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7352 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7352 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7352 KB Output is correct
10 Correct 4 ms 7252 KB Output is correct
11 Correct 173 ms 15072 KB Output is correct
12 Correct 150 ms 13388 KB Output is correct
13 Correct 552 ms 96488 KB Output is correct
14 Correct 203 ms 22720 KB Output is correct
15 Correct 191 ms 22732 KB Output is correct
16 Correct 389 ms 69472 KB Output is correct
17 Correct 542 ms 96500 KB Output is correct
18 Correct 547 ms 97056 KB Output is correct
19 Correct 173 ms 15052 KB Output is correct
20 Correct 152 ms 13352 KB Output is correct
21 Correct 533 ms 96588 KB Output is correct
22 Correct 208 ms 22628 KB Output is correct
23 Correct 181 ms 22752 KB Output is correct
24 Correct 381 ms 69540 KB Output is correct
25 Correct 538 ms 96444 KB Output is correct
26 Correct 544 ms 97100 KB Output is correct
27 Correct 178 ms 13388 KB Output is correct
28 Correct 228 ms 16580 KB Output is correct
29 Correct 832 ms 96464 KB Output is correct
30 Correct 500 ms 55348 KB Output is correct
31 Correct 529 ms 55244 KB Output is correct
32 Correct 803 ms 96552 KB Output is correct
33 Correct 4 ms 7380 KB Output is correct
34 Correct 4 ms 7380 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 4 ms 7352 KB Output is correct
37 Correct 4 ms 7352 KB Output is correct
38 Correct 4 ms 7320 KB Output is correct
39 Correct 4 ms 7380 KB Output is correct
40 Correct 4 ms 7356 KB Output is correct
41 Correct 4 ms 7252 KB Output is correct
42 Correct 4 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 92 ms 9232 KB Output is correct
3 Correct 52 ms 9300 KB Output is correct
4 Correct 149 ms 36920 KB Output is correct
5 Correct 112 ms 37568 KB Output is correct
6 Correct 333 ms 36916 KB Output is correct
7 Correct 64 ms 9348 KB Output is correct
8 Correct 197 ms 36916 KB Output is correct
9 Correct 145 ms 37608 KB Output is correct
10 Correct 168 ms 37716 KB Output is correct
11 Correct 184 ms 23136 KB Output is correct
12 Correct 191 ms 30356 KB Output is correct
13 Correct 174 ms 23184 KB Output is correct
14 Correct 336 ms 37036 KB Output is correct
15 Correct 333 ms 37224 KB Output is correct
16 Correct 4 ms 7252 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7348 KB Output is correct
19 Correct 4 ms 7352 KB Output is correct
20 Correct 5 ms 7300 KB Output is correct
21 Correct 4 ms 7352 KB Output is correct
22 Correct 4 ms 7352 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 4 ms 7272 KB Output is correct
25 Correct 4 ms 7356 KB Output is correct