Submission #1069135

# Submission time Handle Problem Language Result Execution time Memory
1069135 2024-08-21T16:17:17 Z bleahbleah Beech Tree (IOI23_beechtree) C++17
0 / 100
81 ms 74508 KB
#include "beechtree.h"
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ld = long double;

//#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

const int nmax = 1e5 + 5;

vector<pii> g[nmax];
vector<int> P, C;

unordered_set<int> colors[nmax], play[nmax];
bool isanc(unordered_set<int>& A, unordered_set<int>& B) {
   if(sz(A) < sz(B)) return 0;
   for(auto &x : B)
      if(!A.count(x)) return 0;
   return 1;
}

vector<int> sol;
int h[nmax];

vector<int> dfs(int node) {
   //cerr << node << '\n';
   vector<int> here;
   sol[node] = 1;
   h[node] = 0;
   for(auto [x, e] : g[node]) {
      auto T = dfs(x);
      
      //cerr << x << ": " << sol[x] << '\n';
      
      sol[node] &= sol[x];
      copy(all(T), back_inserter(here));
      h[node] = max(h[node], h[x] + 1);
   }
   here.emplace_back(node);
   
   if(sol[node] == 0 || sz(g[node]) != sz(colors[node])) { sol[node] = 0; return here; }
   vector<vector<int>> ts(h[node] + 1);
   for(auto x : here) ts[h[x]].emplace_back(x);
   
   for(auto x : here) play[x] = colors[x];
   
   for(int i = 0; i < h[node]; i++) {
         //if(node == 0) {
            //cerr << "niveaux " << i << '\n';
         //}
      for(auto x : here) {
         if(x == node) continue;
         if(h[x] < i) continue;
         
         //if(node == 0) {
            //cerr << x << '\n';
            //for(auto x : play)
         //}
         
         if(!isanc(play[P[x]], play[x])) { sol[node] = 0; return here; }
      }
      for(auto a : ts[i]) {
         if(a == node) continue;
         play[P[a]].erase(C[a]);
      }
   }
   
   for(auto x : here) {
      for(auto y : here) {
         if(sz(colors[x]) > sz(colors[y])) {
            if(h[x] < h[y]) { sol[node] = 0; return here; }
         }
      }
   }
   
   return here;
}

std::vector<int> beechtree(int N, int M, std::vector<int> P_, std::vector<int> C_) {
   P = P_;
   C = C_;
   for(int i = 1; i < N; i++) {
      g[P[i]].emplace_back(i, C[i]);
      colors[P[i]].emplace(C[i]);
   }
   sol.assign(N, 0);
   dfs(0);
   
   
   return sol;
}

/**
      Töte es durch genaue Untersuchung\Töte es kann es nur noch schlimmer machen\Es lässt es irgendwie atmen
--
*/ 
# Verdict Execution time Memory Grader output
1 Correct 5 ms 13916 KB Output is correct
2 Incorrect 4 ms 13660 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 13744 KB Output is correct
2 Correct 4 ms 13916 KB Output is correct
3 Correct 3 ms 13916 KB Output is correct
4 Correct 4 ms 13748 KB Output is correct
5 Correct 4 ms 13660 KB Output is correct
6 Correct 4 ms 13660 KB Output is correct
7 Correct 4 ms 13660 KB Output is correct
8 Correct 4 ms 13968 KB Output is correct
9 Correct 5 ms 13660 KB Output is correct
10 Correct 4 ms 13660 KB Output is correct
11 Correct 4 ms 13684 KB Output is correct
12 Correct 4 ms 13916 KB Output is correct
13 Correct 5 ms 13660 KB Output is correct
14 Incorrect 4 ms 13916 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 13744 KB Output is correct
2 Correct 4 ms 13916 KB Output is correct
3 Correct 3 ms 13916 KB Output is correct
4 Correct 4 ms 13748 KB Output is correct
5 Correct 4 ms 13660 KB Output is correct
6 Correct 4 ms 13660 KB Output is correct
7 Runtime error 81 ms 74508 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 13520 KB Output is correct
2 Correct 5 ms 13688 KB Output is correct
3 Incorrect 4 ms 13660 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 13744 KB Output is correct
2 Correct 4 ms 13916 KB Output is correct
3 Correct 4 ms 13660 KB Output is correct
4 Correct 4 ms 13968 KB Output is correct
5 Runtime error 81 ms 74508 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 13916 KB Output is correct
2 Incorrect 4 ms 13660 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 13744 KB Output is correct
2 Correct 4 ms 13916 KB Output is correct
3 Correct 4 ms 13660 KB Output is correct
4 Correct 4 ms 13968 KB Output is correct
5 Correct 5 ms 13660 KB Output is correct
6 Correct 4 ms 13660 KB Output is correct
7 Correct 4 ms 13684 KB Output is correct
8 Correct 4 ms 13916 KB Output is correct
9 Correct 5 ms 13660 KB Output is correct
10 Incorrect 4 ms 13916 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 13916 KB Output is correct
2 Incorrect 4 ms 13660 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 13744 KB Output is correct
2 Correct 4 ms 13916 KB Output is correct
3 Correct 4 ms 13660 KB Output is correct
4 Correct 4 ms 13968 KB Output is correct
5 Correct 5 ms 13660 KB Output is correct
6 Correct 4 ms 13660 KB Output is correct
7 Correct 4 ms 13684 KB Output is correct
8 Correct 4 ms 13916 KB Output is correct
9 Correct 5 ms 13660 KB Output is correct
10 Incorrect 4 ms 13916 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 13916 KB Output is correct
2 Incorrect 4 ms 13660 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -