답안 #870625

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870625 2023-11-08T15:14:52 Z TahirAliyev Paths (BOI18_paths) C++17
23 / 100
3000 ms 89684 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int, int>
#define oo 1e18

const int MAX = 3e5 + 5;

vector<int> g[MAX];

ll dp[33][MAX];
int c[MAX];
int n, m, k;

ll rec(int node, int mask){
    if(dp[mask][node] != -1) return dp[mask][node];
    mask |= (1 << c[node]);
    ll ans = 0;
    if(__popcount(mask) >= 2) ans++;
    for(int to : g[node]){
        if(mask & (1 << c[to])){
            continue;
        }
        ans += rec(to, mask);
    }
    return dp[mask][node] = ans;
}

int main(){
    memset(dp, -1, sizeof(dp));
    cin >> n >> m >> k;
    for(int i = 1; i <= n; i++){
        cin >> c[i];
        c[i]--;
    }
    for(int i = 1; i <= m; i++){
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans += rec(i, 0);
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 85844 KB Output is correct
2 Correct 17 ms 85876 KB Output is correct
3 Correct 16 ms 85852 KB Output is correct
4 Correct 17 ms 85852 KB Output is correct
5 Correct 16 ms 85852 KB Output is correct
6 Correct 16 ms 85852 KB Output is correct
7 Correct 16 ms 85840 KB Output is correct
8 Correct 17 ms 85852 KB Output is correct
9 Correct 17 ms 85852 KB Output is correct
10 Correct 17 ms 85848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2135 ms 89684 KB Output is correct
2 Execution timed out 3036 ms 89424 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 85844 KB Output is correct
2 Correct 17 ms 85876 KB Output is correct
3 Correct 16 ms 85852 KB Output is correct
4 Correct 17 ms 85852 KB Output is correct
5 Correct 16 ms 85852 KB Output is correct
6 Correct 16 ms 85852 KB Output is correct
7 Correct 16 ms 85840 KB Output is correct
8 Correct 17 ms 85852 KB Output is correct
9 Correct 17 ms 85852 KB Output is correct
10 Correct 17 ms 85848 KB Output is correct
11 Correct 2135 ms 89684 KB Output is correct
12 Execution timed out 3036 ms 89424 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 85852 KB Output is correct
2 Execution timed out 3071 ms 86864 KB Time limit exceeded
3 Halted 0 ms 0 KB -