답안 #31792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31792 2017-09-09T04:53:26 Z top34051 Burza (COCI16_burza) C++14
0 / 160
0 ms 2024 KB
#include<bits/stdc++.h>
using namespace std;
#define maxn 405
int n,k;
int dp[maxn], mx[2];
vector<int> from[maxn];
void upd(int val) {
    int i;
    for(i=0;i<2;i++) if(mx[i]<val) swap(mx[i],val);
}
void dfs(int x,int last) {
    int i;
    for(i=0;i<from[x].size();i++) if(from[x][i]!=last) dfs(from[x][i],x);
    mx[0] = mx[1] = -1;
    for(i=0;i<from[x].size();i++) if(from[x][i]!=last) upd(dp[from[x][i]]);
    for(i=0;i<2;i++) if(mx[i]!=-1) dp[x] = mx[i] + 1;
}
main() {
    int i,x,y;
    scanf("%d%d",&n,&k);
    for(i=0;i<n-1;i++) {
        scanf("%d%d",&x,&y);
        from[x].push_back(y); from[y].push_back(x);
    }
    dfs(1,0);
    if(dp[1]<=k) printf("DA");
    else printf("NE");
}

Compilation message

burza.cpp: In function 'void dfs(int, int)':
burza.cpp:13:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<from[x].size();i++) if(from[x][i]!=last) dfs(from[x][i],x);
              ^
burza.cpp:15:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<from[x].size();i++) if(from[x][i]!=last) upd(dp[from[x][i]]);
              ^
burza.cpp: At global scope:
burza.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
burza.cpp: In function 'int main()':
burza.cpp:20:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&k);
                        ^
burza.cpp:22:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&x,&y);
                            ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Incorrect 0 ms 2024 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -