Submission #63181

# Submission time Handle Problem Language Result Execution time Memory
63181 2018-08-01T04:13:29 Z 노영훈(#1832) Paths (BOI18_paths) C++11
100 / 100
565 ms 53228 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=300010, inf=2e9;

int n, m, k;
vector<int> G[MX];
int C[MX];

int A[MX][5];
int B[MX][25];

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m>>k;
    for(int i=1; i<=n; i++) cin>>C[i], C[i]--;
    for(int i=1; i<=m; i++){
        int u,v; cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for(int i=1; i<=n; i++) for(int x:G[i]) A[i][C[x]]++;
    for(int i=1; i<=n; i++) A[i][C[i]]=0;
    for(int i=1; i<=n; i++)
        for(int x:G[i])
            for(int j=0; j<k; j++) B[i][C[x]*5+j]+=A[x][j];
    for(int i=1; i<=n; i++) for(int a=0; a<k; a++) for(int b=0; b<k; b++)
        if(a==C[i] || b==C[i]) B[i][a*5+b]=0;

    ll ans=0;
    for(int i=1; i<=n; i++){
        // 2
        for(int a=0; a<k; a++) ans+=A[i][a];

        // 3
        for(int a=0; a<k; a++)
            for(int b=a+1; b<k; b++) ans+=2LL*A[i][a]*A[i][b];
        if(k==3) continue;

        // 4
        for(int a=0; a<k; a++) for(int b=0; b<k; b++) for(int c=0; c<k; c++){
            if(a==b || b==c || c==a) continue;
            ans+=1LL*A[i][a]*B[i][b*5+c];
        }
        if(k==4) continue;

        for(int a=0; a<k; a++) for(int b=0; b<k; b++) for(int c=0; c<k; c++) for(int d=0; d<k; d++){
            if(a==b || a==c || a==d || b==c || b==d || c==d) continue;
            ans+=1LL*B[i][a*5+b]*B[i][c*5+d];
        }

    }

    cout<<ans<<'\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 10 ms 7600 KB Output is correct
3 Correct 8 ms 7600 KB Output is correct
4 Correct 9 ms 7612 KB Output is correct
5 Correct 9 ms 7612 KB Output is correct
6 Correct 10 ms 7612 KB Output is correct
7 Correct 8 ms 7632 KB Output is correct
8 Correct 10 ms 7660 KB Output is correct
9 Correct 9 ms 7676 KB Output is correct
10 Correct 7 ms 7676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 11900 KB Output is correct
2 Correct 79 ms 11900 KB Output is correct
3 Correct 445 ms 52476 KB Output is correct
4 Correct 263 ms 52476 KB Output is correct
5 Correct 135 ms 52476 KB Output is correct
6 Correct 325 ms 52476 KB Output is correct
7 Correct 401 ms 52592 KB Output is correct
8 Correct 428 ms 53116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 10 ms 7600 KB Output is correct
3 Correct 8 ms 7600 KB Output is correct
4 Correct 9 ms 7612 KB Output is correct
5 Correct 9 ms 7612 KB Output is correct
6 Correct 10 ms 7612 KB Output is correct
7 Correct 8 ms 7632 KB Output is correct
8 Correct 10 ms 7660 KB Output is correct
9 Correct 9 ms 7676 KB Output is correct
10 Correct 7 ms 7676 KB Output is correct
11 Correct 96 ms 11900 KB Output is correct
12 Correct 79 ms 11900 KB Output is correct
13 Correct 445 ms 52476 KB Output is correct
14 Correct 263 ms 52476 KB Output is correct
15 Correct 135 ms 52476 KB Output is correct
16 Correct 325 ms 52476 KB Output is correct
17 Correct 401 ms 52592 KB Output is correct
18 Correct 428 ms 53116 KB Output is correct
19 Correct 95 ms 53116 KB Output is correct
20 Correct 73 ms 53116 KB Output is correct
21 Correct 380 ms 53116 KB Output is correct
22 Correct 154 ms 53116 KB Output is correct
23 Correct 155 ms 53116 KB Output is correct
24 Correct 270 ms 53116 KB Output is correct
25 Correct 530 ms 53116 KB Output is correct
26 Correct 565 ms 53228 KB Output is correct
27 Correct 75 ms 53228 KB Output is correct
28 Correct 138 ms 53228 KB Output is correct
29 Correct 455 ms 53228 KB Output is correct
30 Correct 281 ms 53228 KB Output is correct
31 Correct 276 ms 53228 KB Output is correct
32 Correct 494 ms 53228 KB Output is correct
33 Correct 10 ms 53228 KB Output is correct
34 Correct 8 ms 53228 KB Output is correct
35 Correct 8 ms 53228 KB Output is correct
36 Correct 9 ms 53228 KB Output is correct
37 Correct 9 ms 53228 KB Output is correct
38 Correct 8 ms 53228 KB Output is correct
39 Correct 8 ms 53228 KB Output is correct
40 Correct 8 ms 53228 KB Output is correct
41 Correct 8 ms 53228 KB Output is correct
42 Correct 10 ms 53228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 53228 KB Output is correct
2 Correct 35 ms 53228 KB Output is correct
3 Correct 31 ms 53228 KB Output is correct
4 Correct 107 ms 53228 KB Output is correct
5 Correct 76 ms 53228 KB Output is correct
6 Correct 232 ms 53228 KB Output is correct
7 Correct 32 ms 53228 KB Output is correct
8 Correct 106 ms 53228 KB Output is correct
9 Correct 92 ms 53228 KB Output is correct
10 Correct 95 ms 53228 KB Output is correct
11 Correct 135 ms 53228 KB Output is correct
12 Correct 167 ms 53228 KB Output is correct
13 Correct 159 ms 53228 KB Output is correct
14 Correct 254 ms 53228 KB Output is correct
15 Correct 259 ms 53228 KB Output is correct
16 Correct 9 ms 53228 KB Output is correct
17 Correct 11 ms 53228 KB Output is correct
18 Correct 8 ms 53228 KB Output is correct
19 Correct 9 ms 53228 KB Output is correct
20 Correct 9 ms 53228 KB Output is correct
21 Correct 10 ms 53228 KB Output is correct
22 Correct 9 ms 53228 KB Output is correct
23 Correct 11 ms 53228 KB Output is correct
24 Correct 9 ms 53228 KB Output is correct
25 Correct 8 ms 53228 KB Output is correct