답안 #1072275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072275 2024-08-23T16:16:09 Z Wael The Ties That Guide Us (CEOI23_incursion) C++17
0 / 100
201 ms 15004 KB
#include <bits/stdc++.h>
#include "incursion.h"
//#include "sample_grader.cpp"
using namespace std;

vector<int> mark(vector<pair<int, int>> F, int safe) {
    --safe;
    int n = F.size() + 1;
    vector<vector<int>> adj(n);
    for (auto [u, v] : F) {
        --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector<int> sz(n, 1), t(n);
    function<void(int, int)> dfs = [&](int u, int p) {
        for (auto v : adj[u]) {
            if (v == p) {
                continue;
            }
            dfs(v, u);
            sz[u] += sz[v];
        }
        if (u != safe && n - sz[u] >= sz[u]) {
            t[u] = 1;
        }
    };
    dfs(safe, -1);

    return t;
}

void locate(vector<pair<int, int>> F, int curr, int t) {
    --curr;
    int n = F.size() + 1;
    vector<vector<int>> adj(n);
    for (auto [u, v] : F) {
        --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector<int> sz(n, 1), par(n, -1);
    function<void(int, int)> calc = [&](int u, int p) {
        for (auto v : adj[u]) {
            if (v == p) {
                continue;
            }
            calc(v, u);
            sz[u] += sz[v];
        }

        if (n - sz[u] == sz[u]) {
            par[u] = p;
            par[p] = u;
        } else if (n - sz[u] > sz[u]) {
            par[u] = p;
        } else {
            par[p] = u;
        }
    };
    calc(0, -1);

    fill(sz.begin(), sz.end(), 1);
    for (int i = 0; i < n; ++i) {
        if (par[i] == -1) {
            calc(i, -1);
        }
        if (par[par[i]] == i) {
            calc(i, -1);
            sz[par[i]] = n;
            break;
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < adj[i].size(); ++j) {
            int v = adj[i][j];
            if (v == par[i]) {
                swap(adj[i][j], adj[i].back());
                adj[i].pop_back();
                break;
            }
        }
        sort(adj[i].begin(), adj[i].end(), [&](int u, int v) {
            return sz[u] > sz[v];
        });
    }

    vector<int> cnt(n);
    function<void(int)> dfs = [&](int u) {
        ++cnt[u];
        if (t == 1) {
            t = visit(par[u] + 1);
            dfs(par[u]);
        } else {
            if (int(adj[u].size()) < cnt[u]) {
                return;
            }
            t = visit(adj[u][cnt[u] - 1] + 1);
            dfs(adj[u][cnt[u] - 1]);
        }
    };
    dfs(curr);

    return;
}

Compilation message

incursion.cpp: In function 'void locate(std::vector<std::pair<int, int> >, int, int)':
incursion.cpp:78:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         for (int j = 0; j < adj[i].size(); ++j) {
      |                         ~~^~~~~~~~~~~~~~~
interface.cpp: In function 'int main()':
interface.cpp:44:55: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |     if(fread(T.data(), sizeof(int), 2 * N - 2, stdin) != 2 * N - 2) exit(0);
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
interface.cpp:50:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         int l = (numbers.size() == N ? N : 0);
      |                  ~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 764 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 201 ms 15004 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 8020 KB Correct
2 Incorrect 83 ms 8024 KB Not correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 764 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -