Submission #684126

# Submission time Handle Problem Language Result Execution time Memory
684126 2023-01-20T12:53:08 Z Red_Inside Burza (COCI16_burza) C++17
160 / 160
206 ms 210912 KB
#include <bits/stdc++.h>
 
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long
 
using namespace std;
const int maxn=400+10,LOG=17,mod=1e9+7;
int block = 0, timer = 0;
const double eps = 1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
#define bt(i) (1 << (i))
//#define int ll
const int inf=1e9;
#define y1 yy
#define prev pre
#define pii pair <int, int>

int n, cnt, t, del[maxn], ok[maxn][maxn], L[maxn], R[maxn], lf[maxn], rf[maxn];
int dp[1100000][410];
vector <int> edge[maxn];

int dfs(int v, int pred = -1, int deep = 0)
{
	if(deep > t) del[v] = 1;
	int mx = deep;
	for(auto to : edge[v])
	{
		if(to == pred) continue;
		int ret = dfs(to, v, deep + 1);
		mx = max(mx, ret);
	}
	if(mx < t) del[v] = 1;
	return mx;
}

void dfs2(int v, int pred = -1, int deep = 0)
{
	for(auto to : edge[v])
	{
		if(to == pred) continue;
		dfs2(to, v, deep + 1);
		if(lf[v] == 0)
			lf[v] = lf[to];
		rf[v] = rf[to];
	}
	if(deep == t)
	{
		cnt++;
		lf[v] = cnt;
		rf[v] = cnt;
	}
	forn(lf[v], i, rf[v])
	{
		ok[i][deep] = max(ok[i][deep], rf[v]);
	}
}

main()
{
	cin >> n >> t;
	forn(1, i, n - 1)
	{
		int l, r;
		cin >> l >> r;
		edge[l].pb(r);
		edge[r].pb(l);
		L[i] = l;
		R[i] = r;
	}
	dfs(1);
	vector <int> vec;
	forn(1, i, n)
	{
		if(!del[i]) vec.pb(i);
	}
	forn(1, i, n) edge[i].clear();
	forn(1, i, n-1)
	{
		if(!del[L[i]] && !del[R[i]])
		{
			L[i] = lower_bound(all(vec), L[i]) - vec.begin() + 1;
			R[i] = lower_bound(all(vec), R[i]) - vec.begin() + 1;
			edge[L[i]].pb(R[i]);
			edge[R[i]].pb(L[i]);
		}
	}
	n = (int)vec.size();
	if(t * t >= n)
	{
		cout << "DA";
		return 0;
	}
	dfs2(1);
	dp[0][1] = 1;
	forn(1, i, cnt)
	{
		forn(0, mask, (1 << t) - 1)
		{
			if(!dp[mask][i]) continue;
//			cout << mask << " " << i << endl;
			forn(1, j, t)
			{
				if(!((mask>>(j-1))&1) && ok[i][j] != 0)
				{
					dp[(mask | (1 << (j - 1)))][ok[i][j] + 1] = 1;
				}
			}
		}
	}
	if(dp[(1<<t)-1][cnt+1]) cout << "DA";
	else cout << "NE";
}

Compilation message

burza.cpp:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   70 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 26776 KB Output is correct
2 Correct 206 ms 210812 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 210760 KB Output is correct
2 Correct 173 ms 210760 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 179 ms 210728 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 210792 KB Output is correct
2 Correct 178 ms 210736 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 53116 KB Output is correct
2 Correct 204 ms 210736 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 584 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 160 ms 210664 KB Output is correct
2 Correct 187 ms 210756 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 175 ms 210700 KB Output is correct
2 Correct 169 ms 210756 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 210824 KB Output is correct
2 Correct 172 ms 210692 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 178 ms 210784 KB Output is correct
6 Correct 1 ms 840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 52964 KB Output is correct
2 Correct 183 ms 210748 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 26744 KB Output is correct
2 Correct 192 ms 210812 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 624 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 105548 KB Output is correct
2 Correct 192 ms 210912 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 90 ms 105608 KB Output is correct
6 Correct 1 ms 468 KB Output is correct