Submission #1003234

# Submission time Handle Problem Language Result Execution time Memory
1003234 2024-06-20T08:08:15 Z vjudge1 Subtree (INOI20_subtree) C++17
20 / 100
778 ms 1048576 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
  #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define int ll
#define MAX 1000001
#define INF INT_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second 

#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define outputar(a,b){\
    for(int i=0;i<b;i++){\
        cout << a[i] << " ";\
    }\
    cout << endl;\
}
#define outputvec(a){\
    for(auto x:a){\
        cout << (int)x << " ";\
    }\
    cout << endl;\
}
#define reset(a,n,v){\
    for(int i=0;i<n;i++){\
        a[i]=v;\
    }\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
  freopen((filename+".in").c_str(),"r",stdin);
  freopen((filename+".out").c_str(),"w",stdout);
}
int n,q,t=1,m,k,x,y,z,x2,y2,z2,a[MAX],b[MAX],d[MAX],e[MAX];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string s[MAX],str[MAX];
//int e[1001][1001];
string s1,s2,s3;
const int mod = 998244353;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
vector<vector<int>> g;
int res=0;
void dfs(int v,int prev){
    a[v]=1;
    for(auto x:g[v]){
        if(x==prev){
            continue;
        }
        dfs(x,v);
        a[v]*=(a[x]+1);
        a[v]%=MOD;
    }
    res+=a[v]; 
    res%=MOD;
}
bool ok;
void dfs1(int v,int prev){
    a[v]=1;
    for(auto x:g[v]){
        if(b[x]==0 || x==prev){
            continue;
        }
        if(a[x]){
            ok=false; 
            return;
        }
        dfs1(x,v);
    }
}
void solve(){
    cin >> n >> m; 
    g.clear();
    g.resize(n);
    for(int i=0;i<m;i++){
        cin >> x >> y;
        x--; 
        y--;
        g[x].pb(y);
        g[y].pb(x); 
    }
    if(n<=20){
        int res=0;
        int h=(1<<n); 
        for(int i=1;i<h;i++){
            int h1;
            for(int j=0;j<n;j++){
                if((i&(1<<j))){
                    b[j]=1;
                    h1=j;
                }
            }
            ok=true;
            dfs1(h1,-1);
            for(int j=0;j<n;j++){
                if(b[j]==1 && a[j]==0){
                    ok=false;
                }
            }
            if(ok){
                res++;
            }
            else{
            }
            for(int j=0;j<n;j++){
                a[j]=b[j]=0;
            }

        }
        cout << res << "\n";
        return;
    }
    dfs(0,-1);
    cout << res << "\n";
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input13.txt","r",stdin);
    //cin >> t;
    ll cnt1=1;
    while(t--){
        solve();
        cnt1++; 
    }
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:74:19: warning: 'h1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   74 |     for(auto x:g[v]){
      |                   ^
Main.cpp:100:17: note: 'h1' was declared here
  100 |             int h1;
      |                 ^~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 63068 KB Output is correct
2 Correct 20 ms 63068 KB Output is correct
3 Correct 25 ms 63068 KB Output is correct
4 Correct 24 ms 63068 KB Output is correct
5 Correct 26 ms 63020 KB Output is correct
6 Correct 22 ms 63008 KB Output is correct
7 Correct 20 ms 63068 KB Output is correct
8 Correct 141 ms 63068 KB Output is correct
9 Correct 146 ms 63068 KB Output is correct
10 Correct 146 ms 63068 KB Output is correct
11 Correct 135 ms 63068 KB Output is correct
12 Correct 74 ms 63064 KB Output is correct
13 Correct 150 ms 63320 KB Output is correct
14 Correct 97 ms 63064 KB Output is correct
15 Correct 78 ms 63064 KB Output is correct
16 Correct 147 ms 63064 KB Output is correct
17 Correct 92 ms 63084 KB Output is correct
18 Correct 83 ms 63072 KB Output is correct
19 Correct 101 ms 63068 KB Output is correct
20 Correct 141 ms 63088 KB Output is correct
21 Correct 151 ms 63084 KB Output is correct
22 Correct 86 ms 63068 KB Output is correct
23 Correct 154 ms 63076 KB Output is correct
24 Correct 89 ms 63088 KB Output is correct
25 Correct 27 ms 63108 KB Output is correct
26 Correct 31 ms 62900 KB Output is correct
27 Correct 27 ms 62980 KB Output is correct
28 Correct 29 ms 63088 KB Output is correct
29 Correct 89 ms 63092 KB Output is correct
30 Correct 148 ms 62912 KB Output is correct
31 Correct 89 ms 63068 KB Output is correct
32 Correct 87 ms 63020 KB Output is correct
33 Correct 83 ms 63068 KB Output is correct
34 Correct 150 ms 63048 KB Output is correct
35 Correct 154 ms 63068 KB Output is correct
36 Correct 154 ms 63056 KB Output is correct
37 Correct 178 ms 63080 KB Output is correct
38 Correct 165 ms 63004 KB Output is correct
39 Correct 168 ms 63080 KB Output is correct
40 Correct 149 ms 63064 KB Output is correct
41 Correct 153 ms 63080 KB Output is correct
42 Correct 113 ms 63100 KB Output is correct
43 Correct 93 ms 63068 KB Output is correct
44 Correct 161 ms 63064 KB Output is correct
45 Correct 175 ms 63064 KB Output is correct
46 Correct 158 ms 63088 KB Output is correct
47 Correct 168 ms 63084 KB Output is correct
48 Correct 168 ms 63072 KB Output is correct
49 Correct 159 ms 62944 KB Output is correct
50 Correct 148 ms 63064 KB Output is correct
51 Correct 168 ms 63000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 62980 KB Output is correct
2 Correct 44 ms 63688 KB Output is correct
3 Correct 58 ms 70992 KB Output is correct
4 Correct 56 ms 71112 KB Output is correct
5 Correct 52 ms 71016 KB Output is correct
6 Correct 54 ms 70944 KB Output is correct
7 Correct 68 ms 72784 KB Output is correct
8 Correct 54 ms 72152 KB Output is correct
9 Correct 59 ms 72448 KB Output is correct
10 Correct 52 ms 71508 KB Output is correct
11 Correct 66 ms 70852 KB Output is correct
12 Correct 53 ms 70480 KB Output is correct
13 Correct 52 ms 70480 KB Output is correct
14 Correct 50 ms 71876 KB Output is correct
15 Correct 55 ms 73036 KB Output is correct
16 Correct 51 ms 73024 KB Output is correct
17 Correct 54 ms 70484 KB Output is correct
18 Correct 56 ms 70412 KB Output is correct
19 Correct 64 ms 70440 KB Output is correct
20 Correct 49 ms 71204 KB Output is correct
21 Correct 65 ms 71324 KB Output is correct
22 Correct 53 ms 71264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 63068 KB Output is correct
2 Correct 20 ms 63068 KB Output is correct
3 Correct 25 ms 63068 KB Output is correct
4 Correct 24 ms 63068 KB Output is correct
5 Correct 26 ms 63020 KB Output is correct
6 Correct 22 ms 63008 KB Output is correct
7 Correct 20 ms 63068 KB Output is correct
8 Correct 141 ms 63068 KB Output is correct
9 Correct 146 ms 63068 KB Output is correct
10 Correct 146 ms 63068 KB Output is correct
11 Correct 135 ms 63068 KB Output is correct
12 Correct 74 ms 63064 KB Output is correct
13 Correct 150 ms 63320 KB Output is correct
14 Correct 97 ms 63064 KB Output is correct
15 Correct 78 ms 63064 KB Output is correct
16 Correct 147 ms 63064 KB Output is correct
17 Correct 92 ms 63084 KB Output is correct
18 Correct 83 ms 63072 KB Output is correct
19 Correct 101 ms 63068 KB Output is correct
20 Correct 141 ms 63088 KB Output is correct
21 Correct 151 ms 63084 KB Output is correct
22 Correct 86 ms 63068 KB Output is correct
23 Correct 154 ms 63076 KB Output is correct
24 Correct 89 ms 63088 KB Output is correct
25 Correct 27 ms 63108 KB Output is correct
26 Correct 31 ms 62900 KB Output is correct
27 Correct 27 ms 62980 KB Output is correct
28 Correct 29 ms 63088 KB Output is correct
29 Correct 89 ms 63092 KB Output is correct
30 Correct 148 ms 62912 KB Output is correct
31 Correct 89 ms 63068 KB Output is correct
32 Correct 87 ms 63020 KB Output is correct
33 Correct 83 ms 63068 KB Output is correct
34 Correct 150 ms 63048 KB Output is correct
35 Correct 154 ms 63068 KB Output is correct
36 Correct 154 ms 63056 KB Output is correct
37 Correct 178 ms 63080 KB Output is correct
38 Correct 165 ms 63004 KB Output is correct
39 Correct 168 ms 63080 KB Output is correct
40 Correct 149 ms 63064 KB Output is correct
41 Correct 153 ms 63080 KB Output is correct
42 Correct 113 ms 63100 KB Output is correct
43 Correct 93 ms 63068 KB Output is correct
44 Correct 161 ms 63064 KB Output is correct
45 Correct 175 ms 63064 KB Output is correct
46 Correct 158 ms 63088 KB Output is correct
47 Correct 168 ms 63084 KB Output is correct
48 Correct 168 ms 63072 KB Output is correct
49 Correct 159 ms 62944 KB Output is correct
50 Correct 148 ms 63064 KB Output is correct
51 Correct 168 ms 63000 KB Output is correct
52 Runtime error 778 ms 1048576 KB Execution killed with signal 9
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 63068 KB Output is correct
2 Correct 20 ms 63068 KB Output is correct
3 Correct 25 ms 63068 KB Output is correct
4 Correct 24 ms 63068 KB Output is correct
5 Correct 26 ms 63020 KB Output is correct
6 Correct 22 ms 63008 KB Output is correct
7 Correct 20 ms 63068 KB Output is correct
8 Correct 141 ms 63068 KB Output is correct
9 Correct 146 ms 63068 KB Output is correct
10 Correct 146 ms 63068 KB Output is correct
11 Correct 135 ms 63068 KB Output is correct
12 Correct 74 ms 63064 KB Output is correct
13 Correct 150 ms 63320 KB Output is correct
14 Correct 97 ms 63064 KB Output is correct
15 Correct 78 ms 63064 KB Output is correct
16 Correct 147 ms 63064 KB Output is correct
17 Correct 92 ms 63084 KB Output is correct
18 Correct 83 ms 63072 KB Output is correct
19 Correct 101 ms 63068 KB Output is correct
20 Correct 141 ms 63088 KB Output is correct
21 Correct 151 ms 63084 KB Output is correct
22 Correct 86 ms 63068 KB Output is correct
23 Correct 154 ms 63076 KB Output is correct
24 Correct 89 ms 63088 KB Output is correct
25 Correct 27 ms 63108 KB Output is correct
26 Correct 31 ms 62900 KB Output is correct
27 Correct 27 ms 62980 KB Output is correct
28 Correct 29 ms 63088 KB Output is correct
29 Correct 89 ms 63092 KB Output is correct
30 Correct 148 ms 62912 KB Output is correct
31 Correct 89 ms 63068 KB Output is correct
32 Correct 87 ms 63020 KB Output is correct
33 Correct 83 ms 63068 KB Output is correct
34 Correct 150 ms 63048 KB Output is correct
35 Correct 154 ms 63068 KB Output is correct
36 Correct 154 ms 63056 KB Output is correct
37 Correct 178 ms 63080 KB Output is correct
38 Correct 165 ms 63004 KB Output is correct
39 Correct 168 ms 63080 KB Output is correct
40 Correct 149 ms 63064 KB Output is correct
41 Correct 153 ms 63080 KB Output is correct
42 Correct 113 ms 63100 KB Output is correct
43 Correct 93 ms 63068 KB Output is correct
44 Correct 161 ms 63064 KB Output is correct
45 Correct 175 ms 63064 KB Output is correct
46 Correct 158 ms 63088 KB Output is correct
47 Correct 168 ms 63084 KB Output is correct
48 Correct 168 ms 63072 KB Output is correct
49 Correct 159 ms 62944 KB Output is correct
50 Correct 148 ms 63064 KB Output is correct
51 Correct 168 ms 63000 KB Output is correct
52 Correct 35 ms 62980 KB Output is correct
53 Correct 44 ms 63688 KB Output is correct
54 Correct 58 ms 70992 KB Output is correct
55 Correct 56 ms 71112 KB Output is correct
56 Correct 52 ms 71016 KB Output is correct
57 Correct 54 ms 70944 KB Output is correct
58 Correct 68 ms 72784 KB Output is correct
59 Correct 54 ms 72152 KB Output is correct
60 Correct 59 ms 72448 KB Output is correct
61 Correct 52 ms 71508 KB Output is correct
62 Correct 66 ms 70852 KB Output is correct
63 Correct 53 ms 70480 KB Output is correct
64 Correct 52 ms 70480 KB Output is correct
65 Correct 50 ms 71876 KB Output is correct
66 Correct 55 ms 73036 KB Output is correct
67 Correct 51 ms 73024 KB Output is correct
68 Correct 54 ms 70484 KB Output is correct
69 Correct 56 ms 70412 KB Output is correct
70 Correct 64 ms 70440 KB Output is correct
71 Correct 49 ms 71204 KB Output is correct
72 Correct 65 ms 71324 KB Output is correct
73 Correct 53 ms 71264 KB Output is correct
74 Runtime error 778 ms 1048576 KB Execution killed with signal 9
75 Halted 0 ms 0 KB -