Submission #841671

#TimeUsernameProblemLanguageResultExecution timeMemory
841671BatrrBeech Tree (IOI23_beechtree)C++17
22 / 100
279 ms105044 KiB
#include "beechtree.h" #include <bits/stdc++.h> #define f first #define s second #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<long long, long long> pll; const int N = 300500, inf = 1e9, mod = 998244353; const ll INF = 1e18; vector<pii> g[N]; int n, m; int ans[N]; int P[N], C[N]; int tin[N], timer; vector<int> t[N]; int sz[N]; map<int, int> was[N], dp[N]; bool f(int v, int u) { if (was[v][u]) return dp[v][u]; was[v][u] = 1; for (int i = 0, j = 0; i < g[u].size(); i++) { while (j < g[v].size() && g[v][j].f != g[u][i].f) j++; if (j == g[v].size()) return dp[v][u] = false; if (!f(g[v][j].s, g[u][i].s)) return dp[v][u] = false; } return dp[v][u] = true; } void dfs(int v) { tin[v] = timer++; sz[v] = 1; ans[v] = 1; vector<int> a; for (int i = 0; i + 1 < g[v].size(); i++) ans[v] &= (g[v][i].f != g[v][i + 1].f); for (auto it: g[v]) { int to = it.s; a.pb(to); dfs(to); sz[v] += sz[to]; ans[v] &= ans[to]; ans[v] &= f(v, to); } sort(a.begin(), a.end(), [](int i, int j) { return sz[i] > sz[j]; }); for (int i = 0; i + 1 < a.size(); i++) ans[v] &= f(a[i], a[i + 1]); } vector<int> beechtree(int N, int M, vector<int> PP, vector<int> CC) { n = N; for (int i = 0; i < n; i++) { g[i].clear(); P[i] = PP[i]; C[i] = CC[i]; ans[i] = 0; was[i].clear(); dp[i].clear(); } for (int i = 1; i < n; i++) g[P[i]].pb({C[i], i}); for (int i = 0; i < n; i++) sort(g[i].begin(), g[i].end()); dfs(0); return vector<int>(ans, ans + n); }

Compilation message (stderr)

beechtree.cpp: In function 'bool first(int, int)':
beechtree.cpp:34:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int i = 0, j = 0; i < g[u].size(); i++) {
      |                            ~~^~~~~~~~~~~~~
beechtree.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         while (j < g[v].size() && g[v][j].f != g[u][i].f)
      |                ~~^~~~~~~~~~~~~
beechtree.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         if (j == g[v].size())
      |             ~~^~~~~~~~~~~~~~
beechtree.cpp:38:29: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   38 |             return dp[v][u] = false;
beechtree.cpp:40:29: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   40 |             return dp[v][u] = false;
beechtree.cpp:42:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   42 |     return dp[v][u] = true;
beechtree.cpp: In function 'void dfs(int)':
beechtree.cpp:50:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int i = 0; i + 1 < g[v].size(); i++)
      |                     ~~~~~~^~~~~~~~~~~~~
beechtree.cpp:63:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for (int i = 0; i + 1 < a.size(); i++)
      |                     ~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...