Submission #98722

# Submission time Handle Problem Language Result Execution time Memory
98722 2019-02-25T11:53:53 Z onjo0127 Paths (BOI18_paths) C++11
73 / 100
3000 ms 28152 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> adj[300009];
int C[300009], D[300009][5];

int main() {
    long long a2 = 0, a3 = 0, a4 = 0, a5 = 0;
    int N, M, K; scanf("%d%d%d",&N,&M,&K);
    for(int i=1; i<=N; i++) {scanf("%d",&C[i]); --C[i];}
    for(int i=0; i<M; i++) {
        int u, v; scanf("%d%d",&u,&v);
        if(C[u] != C[v]) a2 += 2;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=1; i<=N; i++) for(auto& it: adj[i]) ++D[i][C[it]];
    for(int i=1; i<=N; i++) {
        for(int a=0; a<5; a++) for(int b=0; b<5; b++) if(a != b && C[i] != a && C[i] != b) a3 += 1LL * D[i][a] * D[i][b];
        for(auto& it: adj[i]) {
            if(C[i] == C[it]) continue;
            for(int a=0; a<5; a++) {
                for(int b=0; b<5; b++) {
                    set<int> st = {C[i], C[it], a, b};
                    if((int)st.size() == 4) a4 += 1LL * D[i][a] * D[it][b];
                }
            }
        }
        vector<int> S;
        for(int a=0; a<5; a++) if(a != C[i]) S.push_back(a);
        do {
            long long a = 0, b = 0;
            for(auto& it: adj[i]) if(C[it] == S[0]) a += D[it][S[1]];
            for(auto& it: adj[i]) if(C[it] == S[2]) b += D[it][S[3]];
            a4 += a * b;
        } while(next_permutation(S.begin(), S.end()));
    }
    printf("%lld", a2 + a3 + a4 + a5);
    return 0;
}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int N, M, K; scanf("%d%d%d",&N,&M,&K);
                  ~~~~~^~~~~~~~~~~~~~~~~~~
paths.cpp:10:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=N; i++) {scanf("%d",&C[i]); --C[i];}
                              ~~~~~^~~~~~~~~~~~
paths.cpp:12:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int u, v; scanf("%d%d",&u,&v);
                   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 7552 KB Output is correct
2 Correct 10 ms 7424 KB Output is correct
3 Correct 11 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 10 ms 7424 KB Output is correct
7 Correct 9 ms 7396 KB Output is correct
8 Correct 12 ms 7424 KB Output is correct
9 Correct 9 ms 7424 KB Output is correct
10 Correct 9 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2148 ms 14112 KB Output is correct
2 Correct 1825 ms 13304 KB Output is correct
3 Correct 2691 ms 27444 KB Output is correct
4 Correct 1636 ms 15932 KB Output is correct
5 Correct 242 ms 15808 KB Output is correct
6 Correct 2595 ms 23352 KB Output is correct
7 Correct 2560 ms 27556 KB Output is correct
8 Correct 2787 ms 28120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 7552 KB Output is correct
2 Correct 10 ms 7424 KB Output is correct
3 Correct 11 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 10 ms 7424 KB Output is correct
7 Correct 9 ms 7396 KB Output is correct
8 Correct 12 ms 7424 KB Output is correct
9 Correct 9 ms 7424 KB Output is correct
10 Correct 9 ms 7424 KB Output is correct
11 Correct 2148 ms 14112 KB Output is correct
12 Correct 1825 ms 13304 KB Output is correct
13 Correct 2691 ms 27444 KB Output is correct
14 Correct 1636 ms 15932 KB Output is correct
15 Correct 242 ms 15808 KB Output is correct
16 Correct 2595 ms 23352 KB Output is correct
17 Correct 2560 ms 27556 KB Output is correct
18 Correct 2787 ms 28120 KB Output is correct
19 Correct 1931 ms 14024 KB Output is correct
20 Correct 2074 ms 13260 KB Output is correct
21 Correct 2810 ms 27416 KB Output is correct
22 Correct 1829 ms 15956 KB Output is correct
23 Correct 258 ms 15864 KB Output is correct
24 Correct 2458 ms 23272 KB Output is correct
25 Correct 2652 ms 27384 KB Output is correct
26 Correct 2505 ms 28152 KB Output is correct
27 Correct 2316 ms 13212 KB Output is correct
28 Correct 2296 ms 14968 KB Output is correct
29 Correct 2916 ms 27456 KB Output is correct
30 Correct 2819 ms 20952 KB Output is correct
31 Execution timed out 3042 ms 20992 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 7424 KB Output is correct
2 Correct 782 ms 9308 KB Output is correct
3 Correct 795 ms 9216 KB Output is correct
4 Correct 835 ms 13920 KB Output is correct
5 Correct 767 ms 14800 KB Output is correct
6 Correct 1026 ms 14072 KB Output is correct
7 Correct 682 ms 9248 KB Output is correct
8 Correct 946 ms 14072 KB Output is correct
9 Correct 986 ms 14704 KB Output is correct
10 Correct 1182 ms 14572 KB Output is correct
11 Correct 787 ms 11708 KB Output is correct
12 Correct 1174 ms 13272 KB Output is correct
13 Correct 971 ms 11632 KB Output is correct
14 Correct 1002 ms 14064 KB Output is correct
15 Correct 1067 ms 13944 KB Output is correct
16 Correct 12 ms 7424 KB Output is correct
17 Correct 12 ms 7424 KB Output is correct
18 Correct 12 ms 7424 KB Output is correct
19 Correct 12 ms 7424 KB Output is correct
20 Correct 9 ms 7424 KB Output is correct
21 Correct 12 ms 7424 KB Output is correct
22 Correct 12 ms 7424 KB Output is correct
23 Correct 11 ms 7424 KB Output is correct
24 Correct 10 ms 7424 KB Output is correct
25 Correct 11 ms 7360 KB Output is correct