답안 #577284

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
577284 2022-06-14T12:23:34 Z keta_tsimakuridze Burza (COCI16_burza) C++17
144 / 160
20 ms 1020 KB
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define f first
#define s second
#define endl "\n"
const int N = 403, mod = 1e9 + 7; //!
int t, dp[1 << 20], h[N], tmin[N], timer, tmout[N], p[N], P[N][N];
vector<int> v, V[N];
int n, k;
void dfs(int u) {
	h[u] = h[p[u]] + 1;
	if(h[u] == k) {
		v.push_back(u); 
		P[++timer][h[u] - 2] = u;
		tmin[u] = tmout[u] = timer;
		return;
	}
	tmin[u] = n + 5;
	for(int i = 0; i < V[u].size(); i++) {
		if(V[u][i] == p[u]) continue;
		p[V[u][i]] = u;
		dfs(V[u][i]);
		tmin[u] = min(tmin[u], tmin[V[u][i]]);
	}
	P[tmin[u]][h[u] - 2] = u;
	tmout[u] = timer;
}
main() {
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin >> n >> k;
	++k;
	if(k > 20) {
		cout << "DA";
		return 0;
	}
	for(int i = 2; i <= n; i++) {
		int u, v;
		cin >> u >> v;
		V[u].push_back(v);
		V[v].push_back(u);
	}
	dfs(1); 
	
	dp[0] = 1;
	bool ans = 0;
	for(int i = 0; i < (1 << k); i++)  {
		ans |= (dp[i] == timer + 1); 
		if(ans) break;
		for(int j = 0; j < k; j++) {
			if(!(i & (1 << j)) && P[dp[i]][j]) {
				dp[i ^ (1 << j)] = max(dp[i ^ (1 << j)], tmout[P[dp[i]][j]] + 1);
			}
		}
	}
	cout << (ans ? "DA" : "NE");
	
}

Compilation message

burza.cpp: In function 'void dfs(int)':
burza.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i = 0; i < V[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~
burza.cpp: At global scope:
burza.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 1012 KB Output is correct
2 Correct 16 ms 1008 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 10 ms 980 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 980 KB Output is correct
2 Correct 15 ms 1012 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 596 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 17 ms 980 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 468 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 980 KB Output is correct
2 Correct 16 ms 976 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 980 KB Output is correct
2 Correct 20 ms 880 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 736 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 980 KB Output is correct
2 Correct 15 ms 1004 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 10 ms 1000 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 596 KB Output is correct
2 Correct 15 ms 980 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 472 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 14 ms 1020 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 724 KB Output is correct
2 Correct 15 ms 980 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 1 ms 468 KB Output is correct