이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL);
#define PI acos(-1.0)
#define eps 1e-9
#define FF first
#define SS second
// VECTOR (6)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define uniq(v) sort(all( (v) )), (v).resize( unique(all( (v) )) - (v).begin() );
// BIT (6)
#define CNTBIT(x) __builtin_popcountll(x)
#define ODDBIT(x) __builtin_parityll(x)
#define MASK(i) (1LL<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define SUBSET(big, small) (((big)&(small))==(small))
#define MINBIT(x) (x)&(-x)
#define FIRSTBIT(x) __builtin_ctzll(x)
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, int> ii;
/* */
template<class T>
bool minimize(T &a, const T &b) {
if(a > b) {a = b; return 1;}
return 0;
}
template<class T>
bool maximize(T &a, const T &b) {
if(a < b) {a = b; return 1;}
return 0;
}
/* */
/* CODE BELOW */
const int N = 400 + 7, M = 20;
const int oo = 1e9 + 7;
const int MOD = 1e9 + 7;
int n, k;
int _dp[MASK(M)];
vector<int> adj[N];
int jump[N][M+1], h[N];
int in[N], out[N], cnt = 0;
void dfs(int u = 1, int p = -1) {
if(h[u] == k) in[u] = out[u] = ++cnt;
else in[u] = oo, out[u] = -oo;
if(h[u]<k) for(int v:adj[u]) if(v!=p) {
h[v] = h[u] + 1;
dfs(v, u);
minimize(in[u], in[v]);
maximize(out[u], out[v]);
}
if(in[u]!=oo) maximize(jump[in[u]][h[u]], out[u]);
}
signed main() {
//freopen("test.inp", "r", stdin);
//freopen("test.out", "w", stdout);
//fastIO;
scanf("%d%d", &n, &k);
if(k*k>=n) {printf("DA"); return 0;}
int u, v;
for(int i=1;i<n;i++) {
scanf("%d%d", &u, &v);
adj[u].pb(v), adj[v].pb(u);
}
dfs();
if(in[1] == oo) {printf("DA"); return 0;}
memset(_dp, -1, sizeof _dp); _dp[0] = 0;
for(int i=0;i<MASK(k);i++) if(_dp[i]!=-1) {
if(_dp[i] == out[1]) {
printf("DA"); return 0;
}
for(int j=(MASK(k)-1)^i;j>0;j-=j&-j) {
int pos = FIRSTBIT(j&-j);
maximize(_dp[i|MASK(pos)], jump[_dp[i]+1][pos+1]);
}
}
printf("NE");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
burza.cpp: In function 'int main()':
burza.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
burza.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | scanf("%d%d", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |