답안 #151150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151150 2019-09-01T21:49:28 Z Blagojce Paths (BOI18_paths) C++11
100 / 100
821 ms 60844 KB
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x),end(x)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
ll const inf = 1e9;
ll const mod = 1e9 + 7;
ld const eps = 1e-9;

int n, m, k;
int col[300005];
vector<int> g[300005];
int dp[300005][33];
void input(){
        memset(dp, -1, sizeof(dp));
        cin >> n >> m >> k;
        fr(i, 0, n){
                cin >> col[i];
                --col[i];
        }
        fr(i, 0, m){
                int a, b;
                cin >> a >> b;
                --a,--b;
                g[a].pb(b);
                g[b].pb(a);
        }
}
ll dfs(int u, int bit){
        if(dp[u][bit] != -1) return dp[u][bit];
        ll cnt = 0;
        for(auto e : g[u]){
                if((bit&(1 << col[e])) == 0){
                        cnt += dfs(e,(bit|(1<<col[e]))) + 1;
                }
        }
        dp[u][bit] = cnt;
        return cnt;
}
void solve(){
        ll ANS = 0;
        fr(i, 0, n){
                ANS += dfs(i, (1 << col[i]));
        }
        cout << ANS << endl;
}


int main()
{
        input();
        solve();
        return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 46072 KB Output is correct
2 Correct 40 ms 46172 KB Output is correct
3 Correct 39 ms 46072 KB Output is correct
4 Correct 40 ms 46076 KB Output is correct
5 Correct 40 ms 46044 KB Output is correct
6 Correct 40 ms 46200 KB Output is correct
7 Correct 39 ms 46144 KB Output is correct
8 Correct 39 ms 46080 KB Output is correct
9 Correct 39 ms 46200 KB Output is correct
10 Correct 39 ms 46072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 333 ms 49720 KB Output is correct
2 Correct 277 ms 49664 KB Output is correct
3 Correct 697 ms 60252 KB Output is correct
4 Correct 413 ms 54100 KB Output is correct
5 Correct 442 ms 54008 KB Output is correct
6 Correct 640 ms 58348 KB Output is correct
7 Correct 685 ms 60240 KB Output is correct
8 Correct 662 ms 60792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 46072 KB Output is correct
2 Correct 40 ms 46172 KB Output is correct
3 Correct 39 ms 46072 KB Output is correct
4 Correct 40 ms 46076 KB Output is correct
5 Correct 40 ms 46044 KB Output is correct
6 Correct 40 ms 46200 KB Output is correct
7 Correct 39 ms 46144 KB Output is correct
8 Correct 39 ms 46080 KB Output is correct
9 Correct 39 ms 46200 KB Output is correct
10 Correct 39 ms 46072 KB Output is correct
11 Correct 333 ms 49720 KB Output is correct
12 Correct 277 ms 49664 KB Output is correct
13 Correct 697 ms 60252 KB Output is correct
14 Correct 413 ms 54100 KB Output is correct
15 Correct 442 ms 54008 KB Output is correct
16 Correct 640 ms 58348 KB Output is correct
17 Correct 685 ms 60240 KB Output is correct
18 Correct 662 ms 60792 KB Output is correct
19 Correct 331 ms 52700 KB Output is correct
20 Correct 277 ms 51832 KB Output is correct
21 Correct 713 ms 60280 KB Output is correct
22 Correct 423 ms 54020 KB Output is correct
23 Correct 402 ms 54008 KB Output is correct
24 Correct 590 ms 58260 KB Output is correct
25 Correct 675 ms 60216 KB Output is correct
26 Correct 655 ms 60844 KB Output is correct
27 Correct 294 ms 52020 KB Output is correct
28 Correct 367 ms 53368 KB Output is correct
29 Correct 821 ms 60232 KB Output is correct
30 Correct 629 ms 56628 KB Output is correct
31 Correct 721 ms 56688 KB Output is correct
32 Correct 737 ms 60152 KB Output is correct
33 Correct 39 ms 46072 KB Output is correct
34 Correct 39 ms 46200 KB Output is correct
35 Correct 40 ms 46180 KB Output is correct
36 Correct 39 ms 46200 KB Output is correct
37 Correct 39 ms 46096 KB Output is correct
38 Correct 39 ms 46072 KB Output is correct
39 Correct 39 ms 46072 KB Output is correct
40 Correct 39 ms 46080 KB Output is correct
41 Correct 39 ms 46072 KB Output is correct
42 Correct 40 ms 46200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 46072 KB Output is correct
2 Correct 132 ms 47096 KB Output is correct
3 Correct 117 ms 47864 KB Output is correct
4 Correct 222 ms 50612 KB Output is correct
5 Correct 194 ms 51420 KB Output is correct
6 Correct 245 ms 50820 KB Output is correct
7 Correct 128 ms 47864 KB Output is correct
8 Correct 247 ms 50684 KB Output is correct
9 Correct 219 ms 51444 KB Output is correct
10 Correct 210 ms 51452 KB Output is correct
11 Correct 201 ms 49268 KB Output is correct
12 Correct 198 ms 50544 KB Output is correct
13 Correct 208 ms 49760 KB Output is correct
14 Correct 246 ms 50808 KB Output is correct
15 Correct 228 ms 50680 KB Output is correct
16 Correct 40 ms 46072 KB Output is correct
17 Correct 39 ms 46072 KB Output is correct
18 Correct 40 ms 46072 KB Output is correct
19 Correct 39 ms 46072 KB Output is correct
20 Correct 40 ms 46140 KB Output is correct
21 Correct 40 ms 46072 KB Output is correct
22 Correct 39 ms 46072 KB Output is correct
23 Correct 39 ms 46200 KB Output is correct
24 Correct 39 ms 46048 KB Output is correct
25 Correct 39 ms 46072 KB Output is correct