답안 #387545

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
387545 2021-04-08T22:46:31 Z kimbj0709 Paths (BOI18_paths) C++14
100 / 100
1291 ms 99880 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 300050
vector<vector<int> > adj(maxn);
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int n,m,k;
  int input1,input2;
  cin >> n >> m >> k;
  vector<int> color(maxn);
  for(int i=0;i<n;i++){
    cin >> color[i];
    color[i]--;
  }
  for(int i=0;i<m;i++){
    cin >> input1 >> input2;
    input1--,input2--;
    adj[input1].push_back(input2);
    adj[input2].push_back(input1);
  }
  int ans = 0;
  int dp[n][(1<<k)];
  memset(dp,0,sizeof(dp));
  for(int i=0;i<n;i++){
    dp[i][(1<<color[i])] = 1;
  }
  int next[n][(1<<k)];
  for(int aa=0;aa<k;aa++){
    memset(next,0,sizeof(next));
    for(int i=0;i<n;i++){
      for(auto j:adj[i]){
        for(int l=0;l<(1<<k);l++){
          if(((1<<color[j])&l)==0){
            int nextnum = (1<<color[j])|l;
            next[j][nextnum] += dp[i][l];
          }
        }
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<(1<<k);j++){
        ans += next[i][j];
        dp[i][j] = next[i][j];
        next[i][j] = 0;
      }
    }
  }
  cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 6 ms 9676 KB Output is correct
3 Correct 6 ms 9676 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 6 ms 9676 KB Output is correct
6 Correct 6 ms 9676 KB Output is correct
7 Correct 6 ms 9676 KB Output is correct
8 Correct 6 ms 9676 KB Output is correct
9 Correct 6 ms 9652 KB Output is correct
10 Correct 6 ms 9676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 20292 KB Output is correct
2 Correct 94 ms 19080 KB Output is correct
3 Correct 631 ms 62412 KB Output is correct
4 Correct 161 ms 23016 KB Output is correct
5 Correct 123 ms 22116 KB Output is correct
6 Correct 456 ms 47712 KB Output is correct
7 Correct 692 ms 62288 KB Output is correct
8 Correct 716 ms 62844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 6 ms 9676 KB Output is correct
3 Correct 6 ms 9676 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 6 ms 9676 KB Output is correct
6 Correct 6 ms 9676 KB Output is correct
7 Correct 6 ms 9676 KB Output is correct
8 Correct 6 ms 9676 KB Output is correct
9 Correct 6 ms 9652 KB Output is correct
10 Correct 6 ms 9676 KB Output is correct
11 Correct 113 ms 20292 KB Output is correct
12 Correct 94 ms 19080 KB Output is correct
13 Correct 631 ms 62412 KB Output is correct
14 Correct 161 ms 23016 KB Output is correct
15 Correct 123 ms 22116 KB Output is correct
16 Correct 456 ms 47712 KB Output is correct
17 Correct 692 ms 62288 KB Output is correct
18 Correct 716 ms 62844 KB Output is correct
19 Correct 114 ms 20284 KB Output is correct
20 Correct 96 ms 19136 KB Output is correct
21 Correct 694 ms 62292 KB Output is correct
22 Correct 146 ms 23000 KB Output is correct
23 Correct 124 ms 22116 KB Output is correct
24 Correct 423 ms 47692 KB Output is correct
25 Correct 664 ms 62352 KB Output is correct
26 Correct 724 ms 62892 KB Output is correct
27 Correct 129 ms 19272 KB Output is correct
28 Correct 188 ms 23192 KB Output is correct
29 Correct 1291 ms 99880 KB Output is correct
30 Correct 777 ms 60048 KB Output is correct
31 Correct 830 ms 60132 KB Output is correct
32 Correct 1254 ms 99880 KB Output is correct
33 Correct 6 ms 9676 KB Output is correct
34 Correct 6 ms 9676 KB Output is correct
35 Correct 6 ms 9680 KB Output is correct
36 Correct 6 ms 9676 KB Output is correct
37 Correct 6 ms 9676 KB Output is correct
38 Correct 6 ms 9744 KB Output is correct
39 Correct 7 ms 9684 KB Output is correct
40 Correct 6 ms 9676 KB Output is correct
41 Correct 7 ms 9676 KB Output is correct
42 Correct 7 ms 9680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9680 KB Output is correct
2 Correct 80 ms 12840 KB Output is correct
3 Correct 35 ms 12592 KB Output is correct
4 Correct 158 ms 27100 KB Output is correct
5 Correct 117 ms 27448 KB Output is correct
6 Correct 475 ms 64632 KB Output is correct
7 Correct 45 ms 12736 KB Output is correct
8 Correct 313 ms 39648 KB Output is correct
9 Correct 207 ms 40032 KB Output is correct
10 Correct 256 ms 39852 KB Output is correct
11 Correct 261 ms 38460 KB Output is correct
12 Correct 286 ms 51732 KB Output is correct
13 Correct 268 ms 38800 KB Output is correct
14 Correct 480 ms 64608 KB Output is correct
15 Correct 489 ms 64756 KB Output is correct
16 Correct 6 ms 9676 KB Output is correct
17 Correct 6 ms 9676 KB Output is correct
18 Correct 6 ms 9676 KB Output is correct
19 Correct 6 ms 9676 KB Output is correct
20 Correct 6 ms 9676 KB Output is correct
21 Correct 6 ms 9676 KB Output is correct
22 Correct 7 ms 9676 KB Output is correct
23 Correct 6 ms 9676 KB Output is correct
24 Correct 6 ms 9676 KB Output is correct
25 Correct 6 ms 9680 KB Output is correct