Submission #441475

# Submission time Handle Problem Language Result Execution time Memory
441475 2021-07-05T08:36:07 Z sam571128 Paths (BOI18_paths) C++17
100 / 100
1339 ms 23212 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] = e;
                                        solve(5);
                                    }
                            }
                    }
            }
    }
    

    cout << ans << "\n";

}
# Verdict Execution time Memory 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 7372 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 4 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 14536 KB Output is correct
2 Correct 84 ms 14444 KB Output is correct
3 Correct 416 ms 22568 KB Output is correct
4 Correct 110 ms 15944 KB Output is correct
5 Correct 107 ms 15768 KB Output is correct
6 Correct 278 ms 19276 KB Output is correct
7 Correct 417 ms 22568 KB Output is correct
8 Correct 435 ms 23040 KB Output is correct
# Verdict Execution time Memory 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 7372 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 4 ms 7372 KB Output is correct
11 Correct 100 ms 14536 KB Output is correct
12 Correct 84 ms 14444 KB Output is correct
13 Correct 416 ms 22568 KB Output is correct
14 Correct 110 ms 15944 KB Output is correct
15 Correct 107 ms 15768 KB Output is correct
16 Correct 278 ms 19276 KB Output is correct
17 Correct 417 ms 22568 KB Output is correct
18 Correct 435 ms 23040 KB Output is correct
19 Correct 107 ms 14600 KB Output is correct
20 Correct 84 ms 14480 KB Output is correct
21 Correct 419 ms 22636 KB Output is correct
22 Correct 114 ms 15940 KB Output is correct
23 Correct 114 ms 15644 KB Output is correct
24 Correct 303 ms 19328 KB Output is correct
25 Correct 441 ms 22524 KB Output is correct
26 Correct 416 ms 23212 KB Output is correct
27 Correct 149 ms 14404 KB Output is correct
28 Correct 194 ms 16076 KB Output is correct
29 Correct 1217 ms 22568 KB Output is correct
30 Correct 685 ms 18352 KB Output is correct
31 Correct 723 ms 18568 KB Output is correct
32 Correct 1245 ms 22652 KB Output is correct
33 Correct 4 ms 7372 KB Output is correct
34 Correct 5 ms 7372 KB Output is correct
35 Correct 4 ms 7372 KB Output is correct
36 Correct 4 ms 7372 KB Output is correct
37 Correct 4 ms 7372 KB Output is correct
38 Correct 4 ms 7372 KB Output is correct
39 Correct 5 ms 7372 KB Output is correct
40 Correct 5 ms 7284 KB Output is correct
41 Correct 5 ms 7372 KB Output is correct
42 Correct 5 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 165 ms 9548 KB Output is correct
3 Correct 32 ms 9580 KB Output is correct
4 Correct 100 ms 12412 KB Output is correct
5 Correct 73 ms 12848 KB Output is correct
6 Correct 1289 ms 12444 KB Output is correct
7 Correct 51 ms 9548 KB Output is correct
8 Correct 267 ms 12308 KB Output is correct
9 Correct 191 ms 12784 KB Output is correct
10 Correct 225 ms 12608 KB Output is correct
11 Correct 594 ms 10704 KB Output is correct
12 Correct 736 ms 11608 KB Output is correct
13 Correct 659 ms 10808 KB Output is correct
14 Correct 1338 ms 12484 KB Output is correct
15 Correct 1339 ms 12660 KB Output is correct
16 Correct 5 ms 7372 KB Output is correct
17 Correct 5 ms 7372 KB Output is correct
18 Correct 4 ms 7372 KB Output is correct
19 Correct 4 ms 7372 KB Output is correct
20 Correct 4 ms 7244 KB Output is correct
21 Correct 4 ms 7372 KB Output is correct
22 Correct 5 ms 7372 KB Output is correct
23 Correct 5 ms 7356 KB Output is correct
24 Correct 4 ms 7372 KB Output is correct
25 Correct 4 ms 7372 KB Output is correct