답안 #436650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
436650 2021-06-24T17:36:22 Z VinnieThePooh32 Burza (COCI16_burza) C++14
0 / 160
1 ms 384 KB
#include <iostream>
#include <vector>
using namespace std;
const int N = 405;

int n, k;
int target = 2;
bool rFull = false;
vector<int> h, depths;
vector<vector<int>> tmpadj, adj;

bool dfs(int node, int parent, int depth, int orgNode) {
    depth++;
    depths[node] = depth;
    if (h[node] == k) {
        return true;
    }
    bool res = false;
    for (int v : tmpadj[node]) if (v != parent) {
        if (node == 1) {
            orgNode = v;
        }
        h[v] = h[node] + 1;
        int nxt = dfs(v, node, depth, orgNode);
        res |= nxt;
        if (nxt) {
            adj[node].push_back(v);
            adj[v].push_back(node);
        }
    }
    return res;
}

void dfs2(int node, int parent) {
    if (depths[node] == target) {
        target++;
        return;
    }
    if (depths[node] == k + 1 && target == k + 2) {
        cout << "NE";
        rFull = true;
        return;
    }
    for (int v : adj[node]) if (v != parent) {
        dfs2(v, node);
        if (rFull) {
            return;
        }

    }
    return;
}

int main()
{
    cin >> n >> k;
    if (k > 20) {
        cout << "DA";
    }
    h.resize(n + 1);
    adj.resize(n + 1);
    tmpadj.resize(n + 1);
    depths.resize(n + 1, 0);
    for (int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        tmpadj[u].push_back(v);
        tmpadj[v].push_back(u);
    }
    if (!dfs(1, -1, 0, 0)) {
        cout << "DA";
    }
    dfs2(1, -1);
    if (!rFull) {
        cout << "DA";
    }
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -