Submission #634321

# Submission time Handle Problem Language Result Execution time Memory
634321 2022-08-24T08:55:04 Z S2speed Subtree (INOI20_subtree) C++17
20 / 100
78 ms 9940 KB
#include<bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")

#define sze(x) (ll)(x.size())
typedef long long ll;
typedef pair<ll , ll> pll;
typedef pair<int , int> pii;

const ll maxn = 1e5 + 17 , md = 1e9 + 7 , inf = 2e16;

ll n , m;
ll dp[maxn];
vector<ll> adj[maxn];

void dDFS(ll r , ll par){
	ll h = 1;
	for(auto i : adj[r]){
		if(i == par) continue;
		dDFS(i , r);
		h *= dp[i] + 1; h %= md;
	}
	dp[r] = h;
	return;
}

void sub2(){
	for(ll i = 1 ; i < n ; i++){
		ll v , u;
		cin>>v>>u; v--; u--;
		adj[v].push_back(u); adj[u].push_back(v);
	}
	dDFS(0 , -1);
	ll ans = 0;
	for(ll i = 0 ; i < n ; i++) ans += dp[i];
	ans %= md;
	cout<<ans<<'\n';
	return;
}

bitset<21> mark;
ll mask , cnt;

bool mDFS(ll r , ll par){
	mark[r] = true; cnt++;
	for(auto i : adj[r]){
		if(i == par) continue;
		if(mark[i]) return false;
		if(!(mask & (1 << i))) continue;
		if(!mDFS(i , r)) return false;
	}
	return true;
}

void sub1(){
	for(ll i = 0 ; i < m ; i++){
		ll v , u;
		cin>>v>>u; v--; u--;
		adj[v].push_back(u); adj[u].push_back(v);
	}
	ll lm = (1 << n) , ans = 0;
	for(mask = 1 ; mask < lm ; mask++){
		cnt = 0;
		mark.reset();
		for(ll j = 0 ; j < n ; j++){
			if(mask & (1 << j)){
				if(mDFS(j , -1) && cnt == __builtin_popcount(mask)){
//					cout<<mask<<' ';
					ans++;
				}
				break;
			}
		}
	}
//	cout<<'\n';
	cout<<ans<<'\n';
	return;
}

int main(){
	ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0);

	cin>>n>>m;
	if(m == n - 1){
		sub2();
		return 0;
	}
	sub1();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 38 ms 2644 KB Output is correct
9 Correct 39 ms 2644 KB Output is correct
10 Correct 35 ms 2644 KB Output is correct
11 Correct 27 ms 2644 KB Output is correct
12 Correct 15 ms 2672 KB Output is correct
13 Correct 57 ms 2652 KB Output is correct
14 Correct 28 ms 2644 KB Output is correct
15 Correct 15 ms 2672 KB Output is correct
16 Correct 31 ms 2672 KB Output is correct
17 Correct 29 ms 2676 KB Output is correct
18 Correct 18 ms 2676 KB Output is correct
19 Correct 19 ms 2644 KB Output is correct
20 Correct 39 ms 2656 KB Output is correct
21 Correct 36 ms 2644 KB Output is correct
22 Correct 23 ms 2644 KB Output is correct
23 Correct 78 ms 2644 KB Output is correct
24 Correct 30 ms 2672 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 17 ms 2676 KB Output is correct
30 Correct 31 ms 2644 KB Output is correct
31 Correct 19 ms 2676 KB Output is correct
32 Correct 16 ms 2680 KB Output is correct
33 Correct 24 ms 2656 KB Output is correct
34 Correct 42 ms 2764 KB Output is correct
35 Correct 33 ms 2656 KB Output is correct
36 Correct 33 ms 2656 KB Output is correct
37 Correct 38 ms 2644 KB Output is correct
38 Correct 35 ms 2644 KB Output is correct
39 Correct 28 ms 2672 KB Output is correct
40 Correct 33 ms 2644 KB Output is correct
41 Correct 33 ms 2644 KB Output is correct
42 Correct 32 ms 2676 KB Output is correct
43 Correct 18 ms 2676 KB Output is correct
44 Correct 41 ms 2644 KB Output is correct
45 Correct 43 ms 2652 KB Output is correct
46 Correct 29 ms 2644 KB Output is correct
47 Correct 29 ms 2676 KB Output is correct
48 Correct 31 ms 2644 KB Output is correct
49 Correct 30 ms 2676 KB Output is correct
50 Correct 29 ms 2644 KB Output is correct
51 Correct 29 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 4 ms 3028 KB Output is correct
3 Correct 47 ms 7184 KB Output is correct
4 Correct 49 ms 7088 KB Output is correct
5 Correct 47 ms 7176 KB Output is correct
6 Correct 38 ms 7124 KB Output is correct
7 Correct 41 ms 9288 KB Output is correct
8 Correct 44 ms 8708 KB Output is correct
9 Correct 48 ms 8816 KB Output is correct
10 Correct 36 ms 7812 KB Output is correct
11 Correct 36 ms 7104 KB Output is correct
12 Correct 75 ms 6604 KB Output is correct
13 Correct 51 ms 6584 KB Output is correct
14 Correct 34 ms 8124 KB Output is correct
15 Correct 39 ms 9676 KB Output is correct
16 Correct 40 ms 9940 KB Output is correct
17 Correct 42 ms 6548 KB Output is correct
18 Correct 54 ms 6588 KB Output is correct
19 Correct 54 ms 6496 KB Output is correct
20 Correct 31 ms 7324 KB Output is correct
21 Correct 30 ms 7428 KB Output is correct
22 Correct 30 ms 7296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 38 ms 2644 KB Output is correct
9 Correct 39 ms 2644 KB Output is correct
10 Correct 35 ms 2644 KB Output is correct
11 Correct 27 ms 2644 KB Output is correct
12 Correct 15 ms 2672 KB Output is correct
13 Correct 57 ms 2652 KB Output is correct
14 Correct 28 ms 2644 KB Output is correct
15 Correct 15 ms 2672 KB Output is correct
16 Correct 31 ms 2672 KB Output is correct
17 Correct 29 ms 2676 KB Output is correct
18 Correct 18 ms 2676 KB Output is correct
19 Correct 19 ms 2644 KB Output is correct
20 Correct 39 ms 2656 KB Output is correct
21 Correct 36 ms 2644 KB Output is correct
22 Correct 23 ms 2644 KB Output is correct
23 Correct 78 ms 2644 KB Output is correct
24 Correct 30 ms 2672 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 17 ms 2676 KB Output is correct
30 Correct 31 ms 2644 KB Output is correct
31 Correct 19 ms 2676 KB Output is correct
32 Correct 16 ms 2680 KB Output is correct
33 Correct 24 ms 2656 KB Output is correct
34 Correct 42 ms 2764 KB Output is correct
35 Correct 33 ms 2656 KB Output is correct
36 Correct 33 ms 2656 KB Output is correct
37 Correct 38 ms 2644 KB Output is correct
38 Correct 35 ms 2644 KB Output is correct
39 Correct 28 ms 2672 KB Output is correct
40 Correct 33 ms 2644 KB Output is correct
41 Correct 33 ms 2644 KB Output is correct
42 Correct 32 ms 2676 KB Output is correct
43 Correct 18 ms 2676 KB Output is correct
44 Correct 41 ms 2644 KB Output is correct
45 Correct 43 ms 2652 KB Output is correct
46 Correct 29 ms 2644 KB Output is correct
47 Correct 29 ms 2676 KB Output is correct
48 Correct 31 ms 2644 KB Output is correct
49 Correct 30 ms 2676 KB Output is correct
50 Correct 29 ms 2644 KB Output is correct
51 Correct 29 ms 2644 KB Output is correct
52 Incorrect 3 ms 2836 KB Output isn't correct
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 38 ms 2644 KB Output is correct
9 Correct 39 ms 2644 KB Output is correct
10 Correct 35 ms 2644 KB Output is correct
11 Correct 27 ms 2644 KB Output is correct
12 Correct 15 ms 2672 KB Output is correct
13 Correct 57 ms 2652 KB Output is correct
14 Correct 28 ms 2644 KB Output is correct
15 Correct 15 ms 2672 KB Output is correct
16 Correct 31 ms 2672 KB Output is correct
17 Correct 29 ms 2676 KB Output is correct
18 Correct 18 ms 2676 KB Output is correct
19 Correct 19 ms 2644 KB Output is correct
20 Correct 39 ms 2656 KB Output is correct
21 Correct 36 ms 2644 KB Output is correct
22 Correct 23 ms 2644 KB Output is correct
23 Correct 78 ms 2644 KB Output is correct
24 Correct 30 ms 2672 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 17 ms 2676 KB Output is correct
30 Correct 31 ms 2644 KB Output is correct
31 Correct 19 ms 2676 KB Output is correct
32 Correct 16 ms 2680 KB Output is correct
33 Correct 24 ms 2656 KB Output is correct
34 Correct 42 ms 2764 KB Output is correct
35 Correct 33 ms 2656 KB Output is correct
36 Correct 33 ms 2656 KB Output is correct
37 Correct 38 ms 2644 KB Output is correct
38 Correct 35 ms 2644 KB Output is correct
39 Correct 28 ms 2672 KB Output is correct
40 Correct 33 ms 2644 KB Output is correct
41 Correct 33 ms 2644 KB Output is correct
42 Correct 32 ms 2676 KB Output is correct
43 Correct 18 ms 2676 KB Output is correct
44 Correct 41 ms 2644 KB Output is correct
45 Correct 43 ms 2652 KB Output is correct
46 Correct 29 ms 2644 KB Output is correct
47 Correct 29 ms 2676 KB Output is correct
48 Correct 31 ms 2644 KB Output is correct
49 Correct 30 ms 2676 KB Output is correct
50 Correct 29 ms 2644 KB Output is correct
51 Correct 29 ms 2644 KB Output is correct
52 Correct 2 ms 2644 KB Output is correct
53 Correct 4 ms 3028 KB Output is correct
54 Correct 47 ms 7184 KB Output is correct
55 Correct 49 ms 7088 KB Output is correct
56 Correct 47 ms 7176 KB Output is correct
57 Correct 38 ms 7124 KB Output is correct
58 Correct 41 ms 9288 KB Output is correct
59 Correct 44 ms 8708 KB Output is correct
60 Correct 48 ms 8816 KB Output is correct
61 Correct 36 ms 7812 KB Output is correct
62 Correct 36 ms 7104 KB Output is correct
63 Correct 75 ms 6604 KB Output is correct
64 Correct 51 ms 6584 KB Output is correct
65 Correct 34 ms 8124 KB Output is correct
66 Correct 39 ms 9676 KB Output is correct
67 Correct 40 ms 9940 KB Output is correct
68 Correct 42 ms 6548 KB Output is correct
69 Correct 54 ms 6588 KB Output is correct
70 Correct 54 ms 6496 KB Output is correct
71 Correct 31 ms 7324 KB Output is correct
72 Correct 30 ms 7428 KB Output is correct
73 Correct 30 ms 7296 KB Output is correct
74 Incorrect 3 ms 2836 KB Output isn't correct
75 Halted 0 ms 0 KB -