Submission #940339

# Submission time Handle Problem Language Result Execution time Memory
940339 2024-03-07T08:15:20 Z vjudge1 Paths (BOI18_paths) C++17
100 / 100
276 ms 98624 KB
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
#define int long long
#define FOR(i, a, b) for ( int i = a ; i <= b ; i++ )
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)
#define Lg(x) 31 - __builtin_clz(x)
 
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
 
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int MAX = 3e5 + 5;
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
void setupIO(){
    #define name "Whisper"
    //Phu Trong from Nguyen Tat Thanh High School for gifted student
    srand(time(NULL));
    cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    cout << fixed << setprecision(10);
}
 
template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }
 
template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
int numNode, numEdge, numColor;
vector<int> G[MAX];
int C[MAX];
 
int dp[MAX][MASK(5)];
int F(int node, int msk){
    int &ret = dp[node][msk];
    if (~ret) return ret;
    ret = 1;
    for (int &v : G[node]){
        if (!BIT(msk, C[v])) ret += F(v, msk | MASK(C[v]));
    }
    return ret;
}
void Whisper(){
    cin >> numNode >> numEdge >> numColor;
    for (int i = 1; i <= numNode; ++i){
        cin >> C[i];
        --C[i];
    }
    for (int i = 1; i <= numEdge; ++i){
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    int ans = 0;
    memset(dp, -1, sizeof dp);
    for (int u = 1; u <= numNode; ++u){
        ans += F(u, MASK(C[u]));
    }
    cout << ans - numNode;
}
 
 
signed main(){
    setupIO();
    int Test = 1;
//    cin >> Test;
    for ( int i = 1 ; i <= Test ; i++ ){
        Whisper();
        if (i < Test) cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 84816 KB Output is correct
2 Correct 13 ms 84908 KB Output is correct
3 Correct 13 ms 84824 KB Output is correct
4 Correct 11 ms 84828 KB Output is correct
5 Correct 11 ms 84828 KB Output is correct
6 Correct 12 ms 84824 KB Output is correct
7 Correct 11 ms 84828 KB Output is correct
8 Correct 11 ms 84940 KB Output is correct
9 Correct 11 ms 84828 KB Output is correct
10 Correct 11 ms 84944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 93524 KB Output is correct
2 Correct 55 ms 93208 KB Output is correct
3 Correct 245 ms 98244 KB Output is correct
4 Correct 91 ms 94956 KB Output is correct
5 Correct 74 ms 95060 KB Output is correct
6 Correct 151 ms 95936 KB Output is correct
7 Correct 220 ms 97852 KB Output is correct
8 Correct 233 ms 98560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 84816 KB Output is correct
2 Correct 13 ms 84908 KB Output is correct
3 Correct 13 ms 84824 KB Output is correct
4 Correct 11 ms 84828 KB Output is correct
5 Correct 11 ms 84828 KB Output is correct
6 Correct 12 ms 84824 KB Output is correct
7 Correct 11 ms 84828 KB Output is correct
8 Correct 11 ms 84940 KB Output is correct
9 Correct 11 ms 84828 KB Output is correct
10 Correct 11 ms 84944 KB Output is correct
11 Correct 74 ms 93524 KB Output is correct
12 Correct 55 ms 93208 KB Output is correct
13 Correct 245 ms 98244 KB Output is correct
14 Correct 91 ms 94956 KB Output is correct
15 Correct 74 ms 95060 KB Output is correct
16 Correct 151 ms 95936 KB Output is correct
17 Correct 220 ms 97852 KB Output is correct
18 Correct 233 ms 98560 KB Output is correct
19 Correct 66 ms 93652 KB Output is correct
20 Correct 56 ms 93268 KB Output is correct
21 Correct 192 ms 97872 KB Output is correct
22 Correct 80 ms 95060 KB Output is correct
23 Correct 76 ms 95036 KB Output is correct
24 Correct 163 ms 95940 KB Output is correct
25 Correct 193 ms 98072 KB Output is correct
26 Correct 223 ms 98624 KB Output is correct
27 Correct 71 ms 93496 KB Output is correct
28 Correct 83 ms 95312 KB Output is correct
29 Correct 272 ms 98084 KB Output is correct
30 Correct 184 ms 95936 KB Output is correct
31 Correct 210 ms 96196 KB Output is correct
32 Correct 276 ms 98052 KB Output is correct
33 Correct 11 ms 84828 KB Output is correct
34 Correct 12 ms 84828 KB Output is correct
35 Correct 11 ms 84828 KB Output is correct
36 Correct 12 ms 84964 KB Output is correct
37 Correct 12 ms 84828 KB Output is correct
38 Correct 13 ms 84824 KB Output is correct
39 Correct 12 ms 84824 KB Output is correct
40 Correct 12 ms 84828 KB Output is correct
41 Correct 11 ms 84828 KB Output is correct
42 Correct 12 ms 84904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 84824 KB Output is correct
2 Correct 37 ms 87632 KB Output is correct
3 Correct 25 ms 87644 KB Output is correct
4 Correct 68 ms 89292 KB Output is correct
5 Correct 46 ms 89800 KB Output is correct
6 Correct 81 ms 89428 KB Output is correct
7 Correct 28 ms 87636 KB Output is correct
8 Correct 62 ms 89528 KB Output is correct
9 Correct 53 ms 89800 KB Output is correct
10 Correct 64 ms 89812 KB Output is correct
11 Correct 61 ms 88164 KB Output is correct
12 Correct 52 ms 89112 KB Output is correct
13 Correct 61 ms 88384 KB Output is correct
14 Correct 69 ms 89428 KB Output is correct
15 Correct 63 ms 89424 KB Output is correct
16 Correct 13 ms 85084 KB Output is correct
17 Correct 12 ms 84828 KB Output is correct
18 Correct 11 ms 84828 KB Output is correct
19 Correct 11 ms 84828 KB Output is correct
20 Correct 12 ms 85008 KB Output is correct
21 Correct 12 ms 84828 KB Output is correct
22 Correct 12 ms 85004 KB Output is correct
23 Correct 12 ms 84936 KB Output is correct
24 Correct 11 ms 84828 KB Output is correct
25 Correct 13 ms 84868 KB Output is correct