Submission #56295

# Submission time Handle Problem Language Result Execution time Memory
56295 2018-07-11T02:47:06 Z model_code Paths (BOI18_paths) C++17
100 / 100
695 ms 171808 KB
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll big = 1000000007;
const ll mod = 998244353;

ll n,m,k;
vector<vl> C(300001, vl());
vl colors;

ll DP1[300001][5] = {0};
ll DP2[300001][5][5] = {0};

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;
    cin >> n >> m >> k;
    for(int c1 = 0; c1 < n; c1++){
        cin >> a;
        a--;
        colors.push_back(a);
    }
    for(int c1 = 0; c1 < m; c1++){
        cin >> a >> b;
        a--;
        b--;
        C[a].push_back(b);
        C[b].push_back(a);
    }

    for(int c1 = 0; c1 < n; c1++){
        for(int c2 = 0; c2 < sz(C[c1]); c2++){
            DP1[c1][colors[C[c1][c2]]]++;
        }
    }

    for(int c1 = 0; c1 < n; c1++){
        for(int c2 = 0; c2 < sz(C[c1]); c2++){
            for(int c3 = 0; c3 < 5; c3++){
                int c4 = colors[C[c1][c2]];
                DP2[c1][min(c3,c4)][max(c3,c4)] += DP1[C[c1][c2]][c3];
            }
        }
    }

    ll ans1 = 0;
    ll ans2 = 0;
    ll ans3 = 0;
    ll ans4 = 0;

    for(int c1 = 0; c1 < n; c1++){
        for(int c2 = 0; c2 < 5; c2++){
            if(c2 == colors[c1])continue;
            ans1 += DP1[c1][c2];
            for(int c3 = c2+1; c3 < 5; c3++){
                if(c3 == colors[c1])continue;
                ans2 += DP1[c1][c2]*DP1[c1][c3];
                ans2 += DP1[c1][c3]*DP1[c1][c2];
                for(int c4 = c3+1; c4 < 5; c4++){
                    if(c4 == colors[c1])continue;
                    ans3 += DP1[c1][c2]*DP2[c1][c3][c4];
                    ans3 += DP1[c1][c3]*DP2[c1][c2][c4];
                    ans3 += DP1[c1][c4]*DP2[c1][c2][c3];
                    for(int c5 = c4+1; c5 < 5; c5++){
                        if(c5 == colors[c1])continue;
                        ans4 += DP2[c1][c2][c3]*DP2[c1][c4][c5];
                        ans4 += DP2[c1][c2][c4]*DP2[c1][c3][c5];
                        ans4 += DP2[c1][c2][c5]*DP2[c1][c3][c4];
                        ans4 += DP2[c1][c3][c4]*DP2[c1][c2][c5];
                        ans4 += DP2[c1][c3][c5]*DP2[c1][c2][c4];
                        ans4 += DP2[c1][c4][c5]*DP2[c1][c2][c3];
                    }
                }
            }
        }
    }

    cout << ans1+ans2+ans3+ans4 << "\n";

    return 0;
}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:32:12: warning: unused variable 'c' [-Wunused-variable]
     ll a,b,c,e;
            ^
paths.cpp:32:14: warning: unused variable 'e' [-Wunused-variable]
     ll a,b,c,e;
              ^
# Verdict Execution time Memory Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 9 ms 7528 KB Output is correct
3 Correct 10 ms 7528 KB Output is correct
4 Correct 11 ms 7528 KB Output is correct
5 Correct 11 ms 7560 KB Output is correct
6 Correct 9 ms 7636 KB Output is correct
7 Correct 9 ms 7700 KB Output is correct
8 Correct 9 ms 7700 KB Output is correct
9 Correct 9 ms 7700 KB Output is correct
10 Correct 8 ms 7700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 18768 KB Output is correct
2 Correct 100 ms 19844 KB Output is correct
3 Correct 695 ms 100544 KB Output is correct
4 Correct 244 ms 100544 KB Output is correct
5 Correct 267 ms 100544 KB Output is correct
6 Correct 470 ms 100544 KB Output is correct
7 Correct 634 ms 115856 KB Output is correct
8 Correct 585 ms 120884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 9 ms 7528 KB Output is correct
3 Correct 10 ms 7528 KB Output is correct
4 Correct 11 ms 7528 KB Output is correct
5 Correct 11 ms 7560 KB Output is correct
6 Correct 9 ms 7636 KB Output is correct
7 Correct 9 ms 7700 KB Output is correct
8 Correct 9 ms 7700 KB Output is correct
9 Correct 9 ms 7700 KB Output is correct
10 Correct 8 ms 7700 KB Output is correct
11 Correct 150 ms 18768 KB Output is correct
12 Correct 100 ms 19844 KB Output is correct
13 Correct 695 ms 100544 KB Output is correct
14 Correct 244 ms 100544 KB Output is correct
15 Correct 267 ms 100544 KB Output is correct
16 Correct 470 ms 100544 KB Output is correct
17 Correct 634 ms 115856 KB Output is correct
18 Correct 585 ms 120884 KB Output is correct
19 Correct 120 ms 120884 KB Output is correct
20 Correct 118 ms 120884 KB Output is correct
21 Correct 577 ms 129936 KB Output is correct
22 Correct 354 ms 129936 KB Output is correct
23 Correct 299 ms 129936 KB Output is correct
24 Correct 459 ms 129936 KB Output is correct
25 Correct 540 ms 145112 KB Output is correct
26 Correct 559 ms 150272 KB Output is correct
27 Correct 115 ms 150272 KB Output is correct
28 Correct 183 ms 150272 KB Output is correct
29 Correct 601 ms 159348 KB Output is correct
30 Correct 436 ms 159348 KB Output is correct
31 Correct 419 ms 159348 KB Output is correct
32 Correct 596 ms 171808 KB Output is correct
33 Correct 10 ms 171808 KB Output is correct
34 Correct 9 ms 171808 KB Output is correct
35 Correct 10 ms 171808 KB Output is correct
36 Correct 10 ms 171808 KB Output is correct
37 Correct 9 ms 171808 KB Output is correct
38 Correct 11 ms 171808 KB Output is correct
39 Correct 9 ms 171808 KB Output is correct
40 Correct 11 ms 171808 KB Output is correct
41 Correct 10 ms 171808 KB Output is correct
42 Correct 8 ms 171808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 171808 KB Output is correct
2 Correct 38 ms 171808 KB Output is correct
3 Correct 56 ms 171808 KB Output is correct
4 Correct 170 ms 171808 KB Output is correct
5 Correct 161 ms 171808 KB Output is correct
6 Correct 156 ms 171808 KB Output is correct
7 Correct 37 ms 171808 KB Output is correct
8 Correct 205 ms 171808 KB Output is correct
9 Correct 117 ms 171808 KB Output is correct
10 Correct 142 ms 171808 KB Output is correct
11 Correct 127 ms 171808 KB Output is correct
12 Correct 104 ms 171808 KB Output is correct
13 Correct 99 ms 171808 KB Output is correct
14 Correct 178 ms 171808 KB Output is correct
15 Correct 154 ms 171808 KB Output is correct
16 Correct 9 ms 171808 KB Output is correct
17 Correct 9 ms 171808 KB Output is correct
18 Correct 11 ms 171808 KB Output is correct
19 Correct 10 ms 171808 KB Output is correct
20 Correct 8 ms 171808 KB Output is correct
21 Correct 11 ms 171808 KB Output is correct
22 Correct 8 ms 171808 KB Output is correct
23 Correct 8 ms 171808 KB Output is correct
24 Correct 10 ms 171808 KB Output is correct
25 Correct 10 ms 171808 KB Output is correct