Submission #995457

#TimeUsernameProblemLanguageResultExecution timeMemory
995457irmuunBeech Tree (IOI23_beechtree)C++17
9 / 100
2061 ms31536 KiB
#include<bits/stdc++.h> #include "beechtree.h" using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() vector<int>beechtree(int n,int m,vector<int>p,vector<int>c){ vector<int>g[n],col[n]; for(int i=1;i<n;i++){ g[p[i]].pb(i); col[p[i]].pb(c[i]); } vector<bool>same(n,false); for(int i=0;i<n;i++){ sort(all(col[i])); for(int j=1;j<col[i].size();j++){ if(col[i][j]==col[i][j-1]){ same[i]=true; } } } vector<int>b(n,0),f(m+1,0); for(int i=0;i<n;i++){ vector<int>u; priority_queue<pair<int,int>>q; q.push({g[i].size(),i}); bool ok=true; while(!q.empty()){ auto [sz,x]=q.top(); u.pb(x); if(same[x]){ ok=false; } q.pop(); for(int y:g[x]){ q.push({g[y].size(),y}); } } if(!ok){ continue; } for(int j=1;j<u.size();j++){ if(g[u[j]].size()>g[u[j-1]].size()){ ok=false; break; } int pos=0; for(int k=0;k<col[u[j]].size();k++){ while(pos<col[u[j-1]].size()&&col[u[j-1]][pos]!=col[u[j]][k]){ pos++; } if(pos==col[u[j-1]].size()){ ok=false; break; } pos++; } if(!ok){ break; } } if(ok){ b[i]=1; } } return b; }

Compilation message (stderr)

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for(int j=1;j<col[i].size();j++){
      |                     ~^~~~~~~~~~~~~~
beechtree.cpp:48:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         for(int j=1;j<u.size();j++){
      |                     ~^~~~~~~~~
beechtree.cpp:54:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             for(int k=0;k<col[u[j]].size();k++){
      |                         ~^~~~~~~~~~~~~~~~~
beechtree.cpp:55:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |                 while(pos<col[u[j-1]].size()&&col[u[j-1]][pos]!=col[u[j]][k]){
      |                       ~~~^~~~~~~~~~~~~~~~~~~
beechtree.cpp:58:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |                 if(pos==col[u[j-1]].size()){
      |                    ~~~^~~~~~~~~~~~~~~~~~~~
#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...