Submission #887658

# Submission time Handle Problem Language Result Execution time Memory
887658 2023-12-15T00:59:01 Z nnhzzz Paths (BOI18_paths) C++14
100 / 100
242 ms 96048 KB
#include<bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i = (a); i<=(b); ++i)
#define REPD(i,a,b) for(int i = (a); i>=(b); --i)
#define REPDIS(i,a,b,c) for(int i = (a); i<=(b); i += c)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int)(x).size()
#define MASK(x) (1LL<<(x))
#define BIT(x,i) (((x)>>(i))&1LL)
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define pii pair<int,int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define fi first
#define se second
#define gcd __gcd
#define ld long double
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define endl "\n"
 #define int ll

//-------------------------------------------------------------------------------------------------------//
int readInt(){
    char c;
    do{
        c = getchar();
    }while(c!='-' && !isdigit(c));
    bool neg = (c=='-');
    int res = neg?0:c-'0';
    while(isdigit(c=getchar())) res = (res<<3)+(res<<1)+(c-'0');
    return neg?-res:res;
}
//-------------------------------------------------------------------------------------------------------//
template<typename T> bool mini(T &a, const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> bool maxi(T &a, const T &b){if(a<b){a=b;return true;}return false;}
//-------------------------------------------------------------------------------------------------------//
const int MAXN = 3e5+7;
const int MOD = 1e9+7;
const int INF = 1e9;
const int LOG = 16;
const ll LINF = 5e17;
const ld EPS = 1e-9;
const ld PI = acos(-1);
//-------------------------------------------------------------------------------------------------------//

int dp[MAXN][MASK(5)],a[MAXN];
vi adj[MAXN];
int n,m,k,res = 0;

void solve(){
    cin >> n >> m >> k;
    REP(i,0,n-1){
        cin >> a[i];
        --a[i];
        dp[i][MASK(a[i])] = 1;;
    }
    REP(i,1,m){
        int u,v; cin >> u >> v;
        --u; --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    REP(state,0,MASK(k)-1){
        REP(u,0,n-1){
            if(dp[u][state]==0) continue;
            res += dp[u][state];
            for(int &v:adj[u]){
                if(state&(MASK(a[v]))) continue;
                dp[v][state|MASK(a[v])] += dp[u][state];
            }
        }
    }
    cout << res-n;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define task "test"
    if(fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    #define task1 "nothing"
    if(fopen(task1".inp","r")){
        freopen(task1".inp","r",stdin);
        freopen(task1".out","w",stdout);
    }
    int test = 1;
    while(test--) solve();
    return 0;
}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
paths.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(task1".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(task1".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 19900 KB Output is correct
2 Correct 43 ms 17756 KB Output is correct
3 Correct 179 ms 95500 KB Output is correct
4 Correct 66 ms 26968 KB Output is correct
5 Correct 62 ms 27168 KB Output is correct
6 Correct 129 ms 69544 KB Output is correct
7 Correct 168 ms 95316 KB Output is correct
8 Correct 166 ms 95824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 55 ms 19900 KB Output is correct
12 Correct 43 ms 17756 KB Output is correct
13 Correct 179 ms 95500 KB Output is correct
14 Correct 66 ms 26968 KB Output is correct
15 Correct 62 ms 27168 KB Output is correct
16 Correct 129 ms 69544 KB Output is correct
17 Correct 168 ms 95316 KB Output is correct
18 Correct 166 ms 95824 KB Output is correct
19 Correct 52 ms 20052 KB Output is correct
20 Correct 43 ms 17756 KB Output is correct
21 Correct 196 ms 95452 KB Output is correct
22 Correct 66 ms 26964 KB Output is correct
23 Correct 62 ms 27216 KB Output is correct
24 Correct 118 ms 68912 KB Output is correct
25 Correct 160 ms 95312 KB Output is correct
26 Correct 166 ms 96048 KB Output is correct
27 Correct 52 ms 17748 KB Output is correct
28 Correct 70 ms 21328 KB Output is correct
29 Correct 239 ms 95324 KB Output is correct
30 Correct 151 ms 56520 KB Output is correct
31 Correct 151 ms 56640 KB Output is correct
32 Correct 242 ms 95520 KB Output is correct
33 Correct 2 ms 10840 KB Output is correct
34 Correct 2 ms 10844 KB Output is correct
35 Correct 2 ms 10844 KB Output is correct
36 Correct 2 ms 10840 KB Output is correct
37 Correct 2 ms 10840 KB Output is correct
38 Correct 2 ms 10844 KB Output is correct
39 Correct 2 ms 10844 KB Output is correct
40 Correct 3 ms 10888 KB Output is correct
41 Correct 2 ms 10844 KB Output is correct
42 Correct 2 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 26 ms 13032 KB Output is correct
3 Correct 16 ms 12984 KB Output is correct
4 Correct 48 ms 38996 KB Output is correct
5 Correct 38 ms 39376 KB Output is correct
6 Correct 74 ms 38992 KB Output is correct
7 Correct 19 ms 12892 KB Output is correct
8 Correct 57 ms 38992 KB Output is correct
9 Correct 62 ms 39176 KB Output is correct
10 Correct 51 ms 39624 KB Output is correct
11 Correct 47 ms 25812 KB Output is correct
12 Correct 49 ms 32328 KB Output is correct
13 Correct 46 ms 26192 KB Output is correct
14 Correct 81 ms 39040 KB Output is correct
15 Correct 71 ms 39104 KB Output is correct
16 Correct 2 ms 10840 KB Output is correct
17 Correct 2 ms 10860 KB Output is correct
18 Correct 2 ms 10844 KB Output is correct
19 Correct 2 ms 10844 KB Output is correct
20 Correct 2 ms 10844 KB Output is correct
21 Correct 2 ms 10844 KB Output is correct
22 Correct 2 ms 10844 KB Output is correct
23 Correct 2 ms 10844 KB Output is correct
24 Correct 2 ms 10844 KB Output is correct
25 Correct 2 ms 10844 KB Output is correct