답안 #1061947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1061947 2024-08-16T15:52:27 Z mychecksedad 참나무 (IOI23_beechtree) C++17
0 / 100
2000 ms 622536 KB
#include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define ll long long
#define ff first
#define ss second
#define vi vector<int>
const int N = 200005;
const ll INF = 1e18;

vector<int> g[N], S[N];
vi res;
bool isok[N];
int antidep[N], tin[N], timer=  0, sz[N], col[N], n, m, par[N], dep[N];
bool ok = 1;
void dfs(int v){
  set<int> s;
  antidep[v] = 0;
  isok[v] = 1;
  int co = 0, node;
  sz[v] = 1;
  tin[v] = timer++;
  S[v].pb(v);
  for(int u: g[v]){
    dep[u] = dep[v] + 1;
    dfs(u);
    sz[v] += sz[u];
    par[u] = v;
    s.insert(col[u]);
    for(int x: S[u]) S[v].pb(x);
    antidep[v] = max(antidep[u] + 1, antidep[v]);
    if(g[u].size() > 0) co++, node = u;
    isok[v] = isok[v] & isok[u];
  }
  sort(all(g[v]), [&](const int &x, const int &y){
    return sz[x] > sz[y];
  });
  if(g[v].size() != s.size() || isok[v] == 0){
    isok[v] = 0;
    res[v] = 0;
    return;
  }

  // cout << v << ' ' << antidep[v] << '\n';
  if(g[v].size() == 0){
    res[v] = 1;
  }else if(s.size() == g[v].size() && antidep[v] == 1){
    res[v] = 1;
  }else{
    sort(all(S[v]), [&](const int &x, const int &y){
      if(dep[x] != dep[y]) return dep[x] < dep[y];
      if(sz[x] != sz[y]) sz[x] > sz[y];
      return tin[x] < tin[y];
    });


    // cout << v << ' ';
    res[v] = 1;
    map<int, int> co;
    for(int i = 0; i + 1 < S[v].size(); ++i){
      // cout << v << ' ' << S[v][i + 1] << '\n';
      set<int> s;
      int u = S[v][i];
      for(int j = 0; j < g[u].size(); ++j) s.insert(col[g[u][j]]); 
      int x = s.size();
      if(dep[u] != dep[S[v][i + 1]]){
        if(par[S[v][i + 1]] != S[v][co[col[S[v][i + 1]]]]){
          // cout << co[col[S[v][i + 1]]] << ' ' << par[S[v][i + 1]] << ' ' << S[v][i + 1] << "f";
          res[v] = 0;
        }
      }
      u = S[v][i + 1];
      for(int j = 0; j < g[u].size(); ++j) s.insert(col[g[u][j]]); 
      int y = s.size();
      if(x != y){
        res[v] = 0;
        break;
      }
      co[col[S[v][i + 1]]]++;
      // cout << S[v][i] << ' ';
    }//cout << '\n';
    // cout << v << ' ' << res[v] << '\n';
  }
}
std::vector<int> beechtree(int nn, int mm, std::vector<int> P, std::vector<int> C)
{n=nn, m=mm;
  res.resize(n);
  for(int i = 1; i < n; ++i){
    g[P[i]].pb(i);
    col[i] = C[i];
  }
  // dfs(0);
  // bool ok = 1;
  // res[n - 1] = 1;
  // for(int i = n - 2; i >= 0; --i){
  //   if(ok == 0){
  //     res[i] = ok;
  //   }else if(C[i] != C[i + 1]){
  //     res[i] = 1;
  //     ok = 0;
  //   }else{
  //     res[i] = 1;
  //   }
  // }
  par[0] = n + 1;
  dep[0] = 0;
  dfs(0);
  return res;
}

Compilation message

beechtree.cpp: In lambda function:
beechtree.cpp:54:32: warning: statement has no effect [-Wunused-value]
   54 |       if(sz[x] != sz[y]) sz[x] > sz[y];
      |                          ~~~~~~^~~~~~~
beechtree.cpp: In function 'void dfs(int)':
beechtree.cpp:62:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i = 0; i + 1 < S[v].size(); ++i){
      |                    ~~~~~~^~~~~~~~~~~~~
beechtree.cpp:66:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |       for(int j = 0; j < g[u].size(); ++j) s.insert(col[g[u][j]]);
      |                      ~~^~~~~~~~~~~~~
beechtree.cpp:75:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |       for(int j = 0; j < g[u].size(); ++j) s.insert(col[g[u][j]]);
      |                      ~~^~~~~~~~~~~~~
beechtree.cpp:22:15: warning: variable 'node' set but not used [-Wunused-but-set-variable]
   22 |   int co = 0, node;
      |               ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Correct 3 ms 12380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12380 KB Output is correct
2 Correct 2 ms 12376 KB Output is correct
3 Correct 2 ms 12508 KB Output is correct
4 Correct 2 ms 12380 KB Output is correct
5 Correct 2 ms 12380 KB Output is correct
6 Correct 2 ms 12380 KB Output is correct
7 Correct 2 ms 12380 KB Output is correct
8 Correct 2 ms 12380 KB Output is correct
9 Correct 2 ms 12380 KB Output is correct
10 Correct 2 ms 12380 KB Output is correct
11 Correct 2 ms 12380 KB Output is correct
12 Correct 2 ms 12380 KB Output is correct
13 Correct 2 ms 12380 KB Output is correct
14 Correct 2 ms 12380 KB Output is correct
15 Correct 2 ms 12380 KB Output is correct
16 Correct 2 ms 12380 KB Output is correct
17 Correct 2 ms 12380 KB Output is correct
18 Correct 2 ms 12380 KB Output is correct
19 Correct 3 ms 12376 KB Output is correct
20 Incorrect 2 ms 12380 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12380 KB Output is correct
2 Correct 2 ms 12376 KB Output is correct
3 Correct 2 ms 12508 KB Output is correct
4 Correct 2 ms 12380 KB Output is correct
5 Correct 2 ms 12380 KB Output is correct
6 Correct 2 ms 12380 KB Output is correct
7 Execution timed out 2067 ms 622536 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Correct 2 ms 12380 KB Output is correct
4 Correct 2 ms 12380 KB Output is correct
5 Correct 2 ms 12484 KB Output is correct
6 Correct 2 ms 12380 KB Output is correct
7 Correct 2 ms 12380 KB Output is correct
8 Correct 2 ms 12380 KB Output is correct
9 Incorrect 2 ms 12376 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12380 KB Output is correct
2 Correct 2 ms 12376 KB Output is correct
3 Correct 2 ms 12380 KB Output is correct
4 Correct 2 ms 12380 KB Output is correct
5 Execution timed out 2067 ms 622536 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Correct 3 ms 12380 KB Output is correct
4 Correct 3 ms 12380 KB Output is correct
5 Correct 2 ms 12376 KB Output is correct
6 Correct 2 ms 12508 KB Output is correct
7 Correct 2 ms 12380 KB Output is correct
8 Correct 2 ms 12380 KB Output is correct
9 Correct 2 ms 12380 KB Output is correct
10 Correct 2 ms 12380 KB Output is correct
11 Correct 2 ms 12380 KB Output is correct
12 Correct 2 ms 12380 KB Output is correct
13 Correct 2 ms 12380 KB Output is correct
14 Correct 2 ms 12380 KB Output is correct
15 Correct 2 ms 12380 KB Output is correct
16 Correct 2 ms 12380 KB Output is correct
17 Correct 2 ms 12380 KB Output is correct
18 Correct 2 ms 12380 KB Output is correct
19 Correct 2 ms 12380 KB Output is correct
20 Correct 2 ms 12380 KB Output is correct
21 Correct 2 ms 12380 KB Output is correct
22 Correct 3 ms 12376 KB Output is correct
23 Incorrect 2 ms 12380 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12380 KB Output is correct
2 Correct 2 ms 12376 KB Output is correct
3 Correct 2 ms 12380 KB Output is correct
4 Correct 2 ms 12380 KB Output is correct
5 Correct 2 ms 12380 KB Output is correct
6 Correct 2 ms 12380 KB Output is correct
7 Correct 2 ms 12380 KB Output is correct
8 Correct 2 ms 12380 KB Output is correct
9 Correct 2 ms 12380 KB Output is correct
10 Correct 2 ms 12380 KB Output is correct
11 Correct 2 ms 12380 KB Output is correct
12 Correct 2 ms 12380 KB Output is correct
13 Correct 2 ms 12380 KB Output is correct
14 Correct 2 ms 12380 KB Output is correct
15 Correct 3 ms 12376 KB Output is correct
16 Incorrect 2 ms 12380 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Correct 3 ms 12380 KB Output is correct
4 Correct 3 ms 12380 KB Output is correct
5 Correct 2 ms 12376 KB Output is correct
6 Correct 2 ms 12508 KB Output is correct
7 Correct 2 ms 12380 KB Output is correct
8 Correct 2 ms 12380 KB Output is correct
9 Correct 2 ms 12380 KB Output is correct
10 Correct 2 ms 12380 KB Output is correct
11 Correct 2 ms 12380 KB Output is correct
12 Correct 2 ms 12380 KB Output is correct
13 Correct 2 ms 12380 KB Output is correct
14 Correct 2 ms 12380 KB Output is correct
15 Correct 2 ms 12380 KB Output is correct
16 Correct 2 ms 12380 KB Output is correct
17 Correct 2 ms 12380 KB Output is correct
18 Correct 2 ms 12380 KB Output is correct
19 Correct 2 ms 12380 KB Output is correct
20 Correct 2 ms 12380 KB Output is correct
21 Correct 2 ms 12380 KB Output is correct
22 Correct 3 ms 12376 KB Output is correct
23 Incorrect 2 ms 12380 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12380 KB Output is correct
2 Correct 2 ms 12376 KB Output is correct
3 Correct 2 ms 12380 KB Output is correct
4 Correct 2 ms 12380 KB Output is correct
5 Correct 2 ms 12380 KB Output is correct
6 Correct 2 ms 12380 KB Output is correct
7 Correct 2 ms 12380 KB Output is correct
8 Correct 2 ms 12380 KB Output is correct
9 Correct 2 ms 12380 KB Output is correct
10 Correct 2 ms 12380 KB Output is correct
11 Correct 2 ms 12380 KB Output is correct
12 Correct 2 ms 12380 KB Output is correct
13 Correct 2 ms 12380 KB Output is correct
14 Correct 2 ms 12380 KB Output is correct
15 Correct 3 ms 12376 KB Output is correct
16 Incorrect 2 ms 12380 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Correct 3 ms 12380 KB Output is correct
4 Correct 3 ms 12380 KB Output is correct
5 Correct 2 ms 12376 KB Output is correct
6 Correct 2 ms 12508 KB Output is correct
7 Correct 2 ms 12380 KB Output is correct
8 Correct 2 ms 12380 KB Output is correct
9 Correct 2 ms 12380 KB Output is correct
10 Correct 2 ms 12380 KB Output is correct
11 Correct 2 ms 12380 KB Output is correct
12 Correct 2 ms 12380 KB Output is correct
13 Correct 2 ms 12380 KB Output is correct
14 Correct 2 ms 12380 KB Output is correct
15 Correct 2 ms 12380 KB Output is correct
16 Correct 2 ms 12380 KB Output is correct
17 Correct 2 ms 12380 KB Output is correct
18 Correct 2 ms 12380 KB Output is correct
19 Correct 2 ms 12380 KB Output is correct
20 Correct 2 ms 12380 KB Output is correct
21 Correct 2 ms 12380 KB Output is correct
22 Correct 3 ms 12376 KB Output is correct
23 Incorrect 2 ms 12380 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
24 Halted 0 ms 0 KB -