Submission #418599

# Submission time Handle Problem Language Result Execution time Memory
418599 2021-06-05T15:22:39 Z parsabahrami Subtree (INOI20_subtree) C++17
8 / 100
245 ms 588 KB
#include <bits/stdc++.h>
 
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second

const int N = 1e6 + 10, MOD = 1e9 + 7;
int M[N]; int msk;

void DFS(vector<vector<int>> &adj, int v) {
	M[v] = 1;
	for (int u : adj[v]) 
		if (!M[u]) DFS(adj, u);
}

int check(vector<vector<int>> &adj, int n) {
	for (int i = 0; i < n; i++) 
		M[i] = 0;
	int rt = -1;
	for (int i = 0; i < n; i++) 
		if (msk & (1 << i)) rt = i;
	DFS(adj, rt);
	for (int i = 0; i < n; i++) 
		if ((msk & (1 << i)) && !M[i]) return 0;
	return 1;
}

vector<pii> E;
int n, m; vector<vector<int>> adj;

int main() {
	int cnt = 0;                                                                                                                           
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) 
		adj.push_back({});
	for (int i = 1; i <= m; i++) {
		int u, v; scanf("%d%d", &u, &v);
		u--, v--;
		E.push_back({u, v});
	}
	for (int i = 1; i < (1 << n); i++) {
		vector<pii> te; msk = i;
		for (pii &e : E)
			if (i & (1 << e.F)) {
				if (i & (1 << e.S)) te.push_back(e);
			}
		if (SZ(te) != __builtin_popcount(i) - 1) continue;
		for (int j = 0; j < n; j++) 
			adj[j] = {};
		for (pii &e : te) {
			adj[e.F].push_back(e.S);
			adj[e.S].push_back(e.F);
		}
		cnt += check(adj, n);
	}
	cout << cnt << endl;
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   int u, v; scanf("%d%d", &u, &v);
      |             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 184 ms 296 KB Output is correct
9 Correct 190 ms 280 KB Output is correct
10 Correct 197 ms 204 KB Output is correct
11 Correct 237 ms 204 KB Output is correct
12 Correct 93 ms 300 KB Output is correct
13 Correct 198 ms 204 KB Output is correct
14 Correct 138 ms 296 KB Output is correct
15 Correct 93 ms 284 KB Output is correct
16 Correct 192 ms 204 KB Output is correct
17 Correct 139 ms 204 KB Output is correct
18 Correct 95 ms 296 KB Output is correct
19 Correct 92 ms 288 KB Output is correct
20 Correct 205 ms 288 KB Output is correct
21 Correct 243 ms 284 KB Output is correct
22 Correct 97 ms 204 KB Output is correct
23 Correct 206 ms 284 KB Output is correct
24 Correct 139 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 6 ms 204 KB Output is correct
29 Correct 89 ms 296 KB Output is correct
30 Correct 197 ms 280 KB Output is correct
31 Correct 116 ms 284 KB Output is correct
32 Correct 96 ms 300 KB Output is correct
33 Correct 101 ms 292 KB Output is correct
34 Correct 197 ms 296 KB Output is correct
35 Correct 226 ms 284 KB Output is correct
36 Correct 218 ms 204 KB Output is correct
37 Correct 245 ms 284 KB Output is correct
38 Correct 206 ms 204 KB Output is correct
39 Correct 190 ms 284 KB Output is correct
40 Correct 174 ms 300 KB Output is correct
41 Correct 200 ms 204 KB Output is correct
42 Correct 112 ms 204 KB Output is correct
43 Correct 90 ms 204 KB Output is correct
44 Correct 208 ms 324 KB Output is correct
45 Correct 235 ms 280 KB Output is correct
46 Correct 232 ms 204 KB Output is correct
47 Correct 240 ms 300 KB Output is correct
48 Correct 203 ms 204 KB Output is correct
49 Correct 196 ms 204 KB Output is correct
50 Correct 202 ms 328 KB Output is correct
51 Correct 186 ms 280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 184 ms 296 KB Output is correct
9 Correct 190 ms 280 KB Output is correct
10 Correct 197 ms 204 KB Output is correct
11 Correct 237 ms 204 KB Output is correct
12 Correct 93 ms 300 KB Output is correct
13 Correct 198 ms 204 KB Output is correct
14 Correct 138 ms 296 KB Output is correct
15 Correct 93 ms 284 KB Output is correct
16 Correct 192 ms 204 KB Output is correct
17 Correct 139 ms 204 KB Output is correct
18 Correct 95 ms 296 KB Output is correct
19 Correct 92 ms 288 KB Output is correct
20 Correct 205 ms 288 KB Output is correct
21 Correct 243 ms 284 KB Output is correct
22 Correct 97 ms 204 KB Output is correct
23 Correct 206 ms 284 KB Output is correct
24 Correct 139 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 6 ms 204 KB Output is correct
29 Correct 89 ms 296 KB Output is correct
30 Correct 197 ms 280 KB Output is correct
31 Correct 116 ms 284 KB Output is correct
32 Correct 96 ms 300 KB Output is correct
33 Correct 101 ms 292 KB Output is correct
34 Correct 197 ms 296 KB Output is correct
35 Correct 226 ms 284 KB Output is correct
36 Correct 218 ms 204 KB Output is correct
37 Correct 245 ms 284 KB Output is correct
38 Correct 206 ms 204 KB Output is correct
39 Correct 190 ms 284 KB Output is correct
40 Correct 174 ms 300 KB Output is correct
41 Correct 200 ms 204 KB Output is correct
42 Correct 112 ms 204 KB Output is correct
43 Correct 90 ms 204 KB Output is correct
44 Correct 208 ms 324 KB Output is correct
45 Correct 235 ms 280 KB Output is correct
46 Correct 232 ms 204 KB Output is correct
47 Correct 240 ms 300 KB Output is correct
48 Correct 203 ms 204 KB Output is correct
49 Correct 196 ms 204 KB Output is correct
50 Correct 202 ms 328 KB Output is correct
51 Correct 186 ms 280 KB Output is correct
52 Incorrect 5 ms 588 KB Output isn't correct
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 184 ms 296 KB Output is correct
9 Correct 190 ms 280 KB Output is correct
10 Correct 197 ms 204 KB Output is correct
11 Correct 237 ms 204 KB Output is correct
12 Correct 93 ms 300 KB Output is correct
13 Correct 198 ms 204 KB Output is correct
14 Correct 138 ms 296 KB Output is correct
15 Correct 93 ms 284 KB Output is correct
16 Correct 192 ms 204 KB Output is correct
17 Correct 139 ms 204 KB Output is correct
18 Correct 95 ms 296 KB Output is correct
19 Correct 92 ms 288 KB Output is correct
20 Correct 205 ms 288 KB Output is correct
21 Correct 243 ms 284 KB Output is correct
22 Correct 97 ms 204 KB Output is correct
23 Correct 206 ms 284 KB Output is correct
24 Correct 139 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 6 ms 204 KB Output is correct
29 Correct 89 ms 296 KB Output is correct
30 Correct 197 ms 280 KB Output is correct
31 Correct 116 ms 284 KB Output is correct
32 Correct 96 ms 300 KB Output is correct
33 Correct 101 ms 292 KB Output is correct
34 Correct 197 ms 296 KB Output is correct
35 Correct 226 ms 284 KB Output is correct
36 Correct 218 ms 204 KB Output is correct
37 Correct 245 ms 284 KB Output is correct
38 Correct 206 ms 204 KB Output is correct
39 Correct 190 ms 284 KB Output is correct
40 Correct 174 ms 300 KB Output is correct
41 Correct 200 ms 204 KB Output is correct
42 Correct 112 ms 204 KB Output is correct
43 Correct 90 ms 204 KB Output is correct
44 Correct 208 ms 324 KB Output is correct
45 Correct 235 ms 280 KB Output is correct
46 Correct 232 ms 204 KB Output is correct
47 Correct 240 ms 300 KB Output is correct
48 Correct 203 ms 204 KB Output is correct
49 Correct 196 ms 204 KB Output is correct
50 Correct 202 ms 328 KB Output is correct
51 Correct 186 ms 280 KB Output is correct
52 Incorrect 1 ms 204 KB Output isn't correct
53 Halted 0 ms 0 KB -