답안 #80795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
80795 2018-10-22T11:03:44 Z farukkastamonuda Paths (BOI18_paths) C++14
100 / 100
424 ms 53192 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7448 KB Output is correct
4 Correct 9 ms 7500 KB Output is correct
5 Correct 9 ms 7500 KB Output is correct
6 Correct 8 ms 7556 KB Output is correct
7 Correct 8 ms 7556 KB Output is correct
8 Correct 8 ms 7572 KB Output is correct
9 Correct 8 ms 7572 KB Output is correct
10 Correct 8 ms 7572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 11796 KB Output is correct
2 Correct 84 ms 11796 KB Output is correct
3 Correct 381 ms 52348 KB Output is correct
4 Correct 123 ms 52348 KB Output is correct
5 Correct 127 ms 52348 KB Output is correct
6 Correct 244 ms 52348 KB Output is correct
7 Correct 395 ms 52472 KB Output is correct
8 Correct 395 ms 53048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7448 KB Output is correct
4 Correct 9 ms 7500 KB Output is correct
5 Correct 9 ms 7500 KB Output is correct
6 Correct 8 ms 7556 KB Output is correct
7 Correct 8 ms 7556 KB Output is correct
8 Correct 8 ms 7572 KB Output is correct
9 Correct 8 ms 7572 KB Output is correct
10 Correct 8 ms 7572 KB Output is correct
11 Correct 92 ms 11796 KB Output is correct
12 Correct 84 ms 11796 KB Output is correct
13 Correct 381 ms 52348 KB Output is correct
14 Correct 123 ms 52348 KB Output is correct
15 Correct 127 ms 52348 KB Output is correct
16 Correct 244 ms 52348 KB Output is correct
17 Correct 395 ms 52472 KB Output is correct
18 Correct 395 ms 53048 KB Output is correct
19 Correct 92 ms 53048 KB Output is correct
20 Correct 70 ms 53048 KB Output is correct
21 Correct 393 ms 53048 KB Output is correct
22 Correct 130 ms 53048 KB Output is correct
23 Correct 132 ms 53048 KB Output is correct
24 Correct 235 ms 53048 KB Output is correct
25 Correct 424 ms 53048 KB Output is correct
26 Correct 372 ms 53192 KB Output is correct
27 Correct 70 ms 53192 KB Output is correct
28 Correct 99 ms 53192 KB Output is correct
29 Correct 421 ms 53192 KB Output is correct
30 Correct 256 ms 53192 KB Output is correct
31 Correct 284 ms 53192 KB Output is correct
32 Correct 410 ms 53192 KB Output is correct
33 Correct 8 ms 53192 KB Output is correct
34 Correct 8 ms 53192 KB Output is correct
35 Correct 8 ms 53192 KB Output is correct
36 Correct 8 ms 53192 KB Output is correct
37 Correct 8 ms 53192 KB Output is correct
38 Correct 9 ms 53192 KB Output is correct
39 Correct 8 ms 53192 KB Output is correct
40 Correct 8 ms 53192 KB Output is correct
41 Correct 8 ms 53192 KB Output is correct
42 Correct 8 ms 53192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 53192 KB Output is correct
2 Correct 29 ms 53192 KB Output is correct
3 Correct 29 ms 53192 KB Output is correct
4 Correct 79 ms 53192 KB Output is correct
5 Correct 66 ms 53192 KB Output is correct
6 Correct 226 ms 53192 KB Output is correct
7 Correct 45 ms 53192 KB Output is correct
8 Correct 96 ms 53192 KB Output is correct
9 Correct 84 ms 53192 KB Output is correct
10 Correct 89 ms 53192 KB Output is correct
11 Correct 118 ms 53192 KB Output is correct
12 Correct 174 ms 53192 KB Output is correct
13 Correct 126 ms 53192 KB Output is correct
14 Correct 218 ms 53192 KB Output is correct
15 Correct 206 ms 53192 KB Output is correct
16 Correct 8 ms 53192 KB Output is correct
17 Correct 8 ms 53192 KB Output is correct
18 Correct 8 ms 53192 KB Output is correct
19 Correct 8 ms 53192 KB Output is correct
20 Correct 10 ms 53192 KB Output is correct
21 Correct 8 ms 53192 KB Output is correct
22 Correct 8 ms 53192 KB Output is correct
23 Correct 7 ms 53192 KB Output is correct
24 Correct 8 ms 53192 KB Output is correct
25 Correct 8 ms 53192 KB Output is correct