제출 #1331973

#제출 시각아이디문제언어결과실행 시간메모리
1331973icebearThe Ties That Guide Us (CEOI23_incursion)C++20
0 / 100
59 ms5016 KiB
/* AUTHOR: TUAN ANH - BUI */
// ~~ icebear ~~
#ifndef meo
    #include "incursion.h"
#endif // meo
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        if (x > y) return x = y, true;
        return false;
    }

template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        if (x < y) return x = y, true;
        return false;
    }

#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebear"
/*END OF TEMPLATE. ICEBEAR AND THE CAT WILL WIN TST26 */

const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 27092008;
const ll INF  = (ll)1e18 + 27092008;
const int N = 2e5 + 5;
vector<int> G[N];
int numNode, tour[N], timer;
bool vis[N];

void loadGraph(vector<pair<int, int>> F) {
    numNode = (int)F.size() + 1;
    FOR(i, 1, numNode) {
        G[i].clear();
        tour[i] = 0;
    }
    timer = 0;
    for(auto e : F) {
        G[e.fi].pb(e.se);
        G[e.se].pb(e.fi);
    }
}

#ifdef meo
    int visit(int v) {
        printf("visit node: %d\n", v);
        fflush(stdout);
        int x; cin >> x;
        return x;
    }
#endif // me

void dfs(int u, int par) {
    tour[++timer] = u;
    for(int v : G[u]) if (v != par)
        dfs(v, u);
}

int calc(int pos) {
    return numNode - pos + (numNode % 2 == 1);
}

vector<int> mark(vector<pair<int, int>> E, int safe) {
    loadGraph(E);
    FOR(i, 1, numNode) if (G[i].size() == 1) {
        dfs(i, -1);
        break;
    }
    int pos = 0;
    FOR(i, 1, numNode) if (tour[i] == safe) {
        pos = i;
        break;
    }

    vector<int> T(numNode, 0);
    FOR(i, 1, numNode) {
        if (i < pos) T[tour[i]-1] = (i - 1 <= calc(i));
        else {
            T[tour[i]-1] = (i - 1 >= calc(i));
        }
    }
    return T;
}

void locate(vector<pair<int, int>> E, int S, int T) {
    loadGraph(E);
    FOR(i, 1, numNode) if (G[i].size() == 1) {
        dfs(i, -1);
        break;
    }
    int pos = 0;
    FOR(i, 1, numNode) if (tour[i] == S)
        pos = i;

    vector<bool> vis(numNode + 5, false);
    while(!vis[S]) {
        vis[S] = true;
        if (T == 0) {
            if (pos == 1 || pos == numNode) break;
            if (pos - 1 < calc(pos)) {
                T = visit(S = tour[--pos]);
            } else T = visit(S = tour[++pos]);
        } else {
            if (pos - 1 >= calc(pos)) {
                T = visit(S = tour[--pos]);
            } else T = visit(S = tour[++pos]);
        }
    }
    cerr << S << '\n';
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...