Submission #1099990

#TimeUsernameProblemLanguageResultExecution timeMemory
1099990marvinthangThe Ties That Guide Us (CEOI23_incursion)C++17
100 / 100
308 ms16256 KiB
/************************************* * author: marvinthang * * created: 25.08.2023 10:13:26 * *************************************/ #include "incursion.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define left ___left #define right ___right #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define MASK(i) (1LL << (i)) #define BIT(x, i) ((x) >> (i) & 1) #define __builtin_popcount __builtin_popcountll #define ALL(v) (v).begin(), (v).end() #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define REPD(i, n) for (int i = (n); i-- > 0; ) #define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define FORD(i, b, a) for (int i = (b), _a = (a); --i >= _a; ) #define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u) #define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u) #ifdef LOCAL #include "debug.h" #else #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define DB(...) 23 #define db(...) 23 #define debug(...) 23 #endif template <class U, class V> scan_op(pair <U, V>) { return in >> u.first >> u.second; } template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; } template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; } template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); } template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); } template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; } // end of template vector<int> mark(vector<pair<int, int>> F, int safe) { int N = F.size() + 1; vector <int> sz(N), par(N, -1); vector <vector <int>> adj(N); for (auto [u, v]: F) { --u; --v; adj[u].push_back(v); adj[v].push_back(u); } function<void(int)> dfs = [&] (int u) { sz[u] = 1; for (int v: adj[u]) if (v != par[u]) { par[v] = u; dfs(v); sz[u] += sz[v]; } }; dfs(--safe); vector <int> res(N); REP(u, N) if (u != safe) { vector <int> val; res[u] = 1; for (int v: adj[u]) if (v != par[u] && N - sz[u] < sz[v]) { res[u] = 0; break; } } return res; } void locate(vector<pair<int, int>> F, int u, int t) { int N = F.size() + 1; vector <int> sz(N + 1), par(N + 1, -1); vector <vector <int>> adj(N + 1); for (auto [u, v]: F) { adj[u].push_back(v); adj[v].push_back(u); } function<void(int)> dfs = [&] (int u) { sz[u] = 1; for (int v: adj[u]) if (v != par[u]) { par[v] = u; dfs(v); sz[u] += sz[v]; } }; dfs(1); auto get_size = [&] (int u, int p) { return par[p] == u ? N - sz[p] : sz[u]; }; int last = u; vector <pair <int, int>> nxt; for (int v: adj[u]) nxt.emplace_back(get_size(v, u), v); sort(ALL(nxt)); if (!t && nxt[0].fi == nxt.back().fi) return; if (adj[u].size() == 1) { t = visit(u = adj[u][0]); } else { if (t) { if (nxt.size() == 1 || nxt.back().fi != nxt.end()[-2].fi) { u = nxt.back().se; t = visit(u); } else { for (auto [sz, v]: nxt) if (sz == nxt.back().fi) { if (visit(v)) { visit(u); } else { u = v; t = 0; break; } } } } else { if (nxt[1].fi == nxt.back().fi) { if (visit(nxt[0].se)) { visit(u); return; } u = nxt[0].se; t = 0; } else { if (visit(nxt[1].se)) { visit(u); if (visit(nxt[0].se)) { visit(u); return; } u = nxt[0].se; t = 0; } else { u = nxt[1].se; t = 0; } } } } while (true) { vector <pair <int, int>> nxt_move, nxt; for (int v: adj[u]) { nxt.emplace_back(get_size(v, u), v); if (v != last) nxt_move.push_back(nxt.back()); } sort(ALL(nxt)); sort(ALL(nxt_move)); last = u; if (!t && (nxt_move.empty() || nxt[0].fi == nxt.back().fi)) return; assert(nxt.size() > 1); if (t) { if (nxt_move.size() == 1 || nxt_move[1].fi > nxt_move[0].fi) { u = nxt_move.back().se; t = visit(u); } else { for (auto [sz, v]: nxt_move) { if (visit(v)) { visit(u); } else { u = v; t = 0; break; } } } } else { if (nxt_move.size() == 1 || nxt_move[1].fi == nxt.back().fi) { if (nxt_move[0].fi == nxt.back().fi) return; if (visit(nxt_move[0].se)) { visit(u); return; } u = nxt_move[0].se; t = 0; } else { if (visit(nxt_move[1].se)) { visit(u); if (visit(nxt_move[0].se)) { visit(u); return; } u = nxt_move[0].se; t = 0; } else { u = nxt_move[1].se; t = 0; } } } } }

Compilation message (stderr)

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);
      |                  ~~~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...