Submission #436640

# Submission time Handle Problem Language Result Execution time Memory
436640 2021-06-24T17:29:37 Z VinnieThePooh32 Burza (COCI16_burza) C++14
0 / 160
1 ms 332 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<bool> rootChildren;
vector<vector<int>> tmpadj, adj;

bool dfs(int node, int parent, int depth, int orgNode) {
    depth++;
    depths[node] = depth;
    if (h[node] == k) {
        rootChildren[orgNode] = true;
        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) {
        if (node == 1 && !rootChildren[v]) {
            continue;
        }
        dfs2(v, node);
        if (rFull) {
            return;
        }

    }
    return;
}

void print(vector<vector<int>> a, string name) {
    cout << name << ": [\n";
    for (vector<int> i : a) { 
        cout << "   ";
        for (int j : i) {
            cout << j << ", ";
        }
        cout << "\n";
    }
    cout << "\n]\n";
}

void print2(vector<int> a, string name) {
    cout << name << ": ";
    for (int i : a) {
        cout << i << ", ";
    }
}

void print3(vector<bool> a, string name) {
    cout << name << ": ";
    for (int i : a) {
        cout << i << ", ";
    }
}

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);
    rootChildren.resize(n + 1);
    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";
    }
    print(adj, "adj");
    dfs2(1, -1);
    if (!rFull) {
        cout << "DA";
    }
    
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -