답안 #441471

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441471 2021-07-05T08:29:55 Z sam571128 Paths (BOI18_paths) C++17
70 / 100
1395 ms 23112 KB
#include <bits/stdc++.h>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 3e5+5;
vector<int> adj[N];
int col[N], cnt[N], arr[N];
int ans = 0;
int n,m,k;

void solve(int kk){
    for(int u = 1;u <= n;u++){
        if(col[u]==arr[0]) cnt[u] = 1;
        else cnt[u] = 0;
    }

    for(int i = 0;i < kk-1;i++){
        for(int u = 1;u <= n;u++){
            if(col[u]!=arr[i]) continue;
            for(auto v : adj[u]){
                if(col[v]==arr[i+1]) cnt[v] += cnt[u];
            }
        }
    }


    for(int u = 1;u <= n;u++){
        if(col[u]==arr[kk-1]) ans += cnt[u];
    }
}

signed main(){
    fastio
    cin >> n >> m >> k;
    for(int i = 1;i <= n;i++){
        cin >> col[i];
    }
    for(int i = 0;i < m;i++){
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    for(int a = 1;a <= k;a++){ 
        arr[0] = a;
        if(k>=2)
            for(int b = 1;b <= k;b++){
                if(a==b) continue;
                arr[1] = b;
                solve(2);
                if(k>=3)
                    for(int c = 1;c <= k;c++){
                        if(a==c||b==c) continue;
                        arr[2] = c;
                        solve(3);
                        if(k>=4)
                            for(int d = 1;d <= k;d++){
                                if(a==d||b==d||c==d) continue;
                                arr[3] = d;
                                solve(4);
                                if(k>=5)
                                    for(int e = 1; e <= k;e++){
                                        if(a==e||b==e||c==e||d==e) continue;
                                        arr[4] = d;
                                        solve(5);
                                    }
                            }
                    }
            }
    }
    

    cout << ans << "\n";

}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 4 ms 7372 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 5 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 14548 KB Output is correct
2 Correct 84 ms 14404 KB Output is correct
3 Correct 434 ms 22572 KB Output is correct
4 Correct 117 ms 15844 KB Output is correct
5 Correct 110 ms 15804 KB Output is correct
6 Correct 279 ms 19260 KB Output is correct
7 Correct 458 ms 22664 KB Output is correct
8 Correct 430 ms 23056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 5 ms 7372 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 4 ms 7372 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 5 ms 7372 KB Output is correct
11 Correct 102 ms 14548 KB Output is correct
12 Correct 84 ms 14404 KB Output is correct
13 Correct 434 ms 22572 KB Output is correct
14 Correct 117 ms 15844 KB Output is correct
15 Correct 110 ms 15804 KB Output is correct
16 Correct 279 ms 19260 KB Output is correct
17 Correct 458 ms 22664 KB Output is correct
18 Correct 430 ms 23056 KB Output is correct
19 Correct 105 ms 14532 KB Output is correct
20 Correct 86 ms 14428 KB Output is correct
21 Correct 426 ms 22548 KB Output is correct
22 Correct 121 ms 15940 KB Output is correct
23 Correct 114 ms 15628 KB Output is correct
24 Correct 271 ms 19244 KB Output is correct
25 Correct 411 ms 22468 KB Output is correct
26 Correct 431 ms 23112 KB Output is correct
27 Correct 159 ms 14576 KB Output is correct
28 Correct 209 ms 16128 KB Output is correct
29 Correct 1314 ms 22660 KB Output is correct
30 Correct 718 ms 18504 KB Output is correct
31 Correct 767 ms 18616 KB Output is correct
32 Correct 1395 ms 22584 KB Output is correct
33 Correct 4 ms 7372 KB Output is correct
34 Correct 5 ms 7372 KB Output is correct
35 Correct 5 ms 7372 KB Output is correct
36 Correct 5 ms 7372 KB Output is correct
37 Correct 4 ms 7372 KB Output is correct
38 Correct 5 ms 7372 KB Output is correct
39 Correct 5 ms 7372 KB Output is correct
40 Correct 5 ms 7372 KB Output is correct
41 Correct 5 ms 7372 KB Output is correct
42 Correct 4 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Incorrect 164 ms 9676 KB Output isn't correct
3 Halted 0 ms 0 KB -