Submission #938794

#TimeUsernameProblemLanguageResultExecution timeMemory
938794AdamGSBeech Tree (IOI23_beechtree)C++17
100 / 100
411 ms67780 KiB
#include "beechtree.h" #include<bits/stdc++.h> using namespace std; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=2e5+7; vector<pair<int,int>>V[LIM], K[LIM]; vector<int>ans; int ile[LIM]; void DFS(int x) { ile[x]=1; for(auto i : V[x]) { DFS(i.nd); ile[x]+=ile[i.nd]; K[x].pb({ile[i.nd], i.nd}); } sort(all(K[x])); reverse(all(K[x])); for(int i=1; i<V[x].size(); ++i) if(V[x][i-1].st==V[x][i].st) ans[x]=0; } bool zawiera(int a, int b) { if(V[a].size()>V[b].size()) return false; int l=0; rep(i, V[a].size()) { while(l<V[b].size() && V[b][l].st!=V[a][i].st) ++l; if(l==V[b].size()) return false; if(ile[V[a][i].nd]>ile[V[b][l].nd]) return false; } return true; } bool dodaj(set<pair<int,int>>&S, pair<int,int>x) { auto it=S.lower_bound(x); if(it!=S.end()) { auto p=*it; if(!zawiera(x.nd, p.nd)) return false; } if(it!=S.begin()) { --it; auto p=*it; if(!zawiera(p.nd, x.nd)) return false; } S.insert(x); return true; } void DFS2(int x, set<pair<int,int>>&S) { if(K[x].size()==0) { S.insert({ile[x], x}); return; } DFS2(K[x][0].nd, S); if(!ans[K[x][0].nd]) ans[x]=0; if(!dodaj(S, {ile[x], x})) ans[x]=0; for(int i=1; i<K[x].size(); ++i) { set<pair<int,int>>tmp; DFS2(K[x][i].nd, tmp); if(!ans[K[x][i].nd]) ans[x]=0; if(!ans[x]) continue; for(auto j : tmp) if(!dodaj(S, j)) ans[x]=0; } } vector<int>beechtree(int n, int m, vector<int>P, vector<int>C) { rep(i, n-1) V[P[i+1]].pb({C[i+1], i+1}); rep(i, n) sort(all(V[i])); rep(i, n) ans.pb(1); DFS(0); set<pair<int,int>>S; DFS2(0, S); return ans; }

Compilation message (stderr)

beechtree.cpp: In function 'void DFS(int)':
beechtree.cpp:22:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |   for(int i=1; i<V[x].size(); ++i) if(V[x][i-1].st==V[x][i].st) ans[x]=0;
      |                ~^~~~~~~~~~~~
beechtree.cpp: In function 'bool zawiera(int, int)':
beechtree.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
beechtree.cpp:27:3: note: in expansion of macro 'rep'
   27 |   rep(i, V[a].size()) {
      |   ^~~
beechtree.cpp:28:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     while(l<V[b].size() && V[b][l].st!=V[a][i].st) ++l;
      |           ~^~~~~~~~~~~~
beechtree.cpp:29:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     if(l==V[b].size()) return false;
      |        ~^~~~~~~~~~~~~
beechtree.cpp: In function 'void DFS2(int, std::set<std::pair<int, int> >&)':
beechtree.cpp:56:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for(int i=1; i<K[x].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...