Submission #468971

# Submission time Handle Problem Language Result Execution time Memory
468971 2021-08-30T09:58:06 Z sinamhdv Subtree (INOI20_subtree) C++11
0 / 100
2000 ms 204 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const ll LINF = 1e18 + 100;

#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define fast_io ios::sync_with_stdio(0); cin.tie(0);
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int MAXN = 22;

int n, m;
int adj[MAXN];
int ans;
int cn;

int dpar[MAXN];

inline int getroot(int x)
{
	return dpar[x] == x ? x : dpar[x] = getroot(dpar[x]);
}

inline void merge(int x, int y)
{
	x =  getroot(x);
	y = getroot(y);
	if (x == y) return;
	dpar[x] = y;
	cn--;
}

int32_t main(void)
{
	fast_io;
	cin >> n >> m;
	FOR(i, 0, m)
	{
		int x, y;
		cin >> x >> y;
		x--; y--;
		adj[x] |= (1 << y);
		adj[y] |= (1 << x);
	}

	FOR(mask, 1, 1 << n)
	{
		int e = 0;
		int sz = __builtin_popcount(mask);
		FOR(i, 0, n) if (mask >> i & 1) e += __builtin_popcount(adj[i] & mask);
		e /= 2;
		if (e != sz - 1) continue;
		iota(dpar, dpar + n + 1, 0);
		cn = sz;
		FOR(i, 0, n) if (mask >> i & 1) FOR(j, 0, n) if ((mask >> j & 1) && i != j) merge(i, j);
		if (cn == 1) ans++;
	}

	cout << ans << endl;


	return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -