답안 #938791

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938791 2024-03-05T14:28:01 Z AdamGS 참나무 (IOI23_beechtree) C++17
58 / 100
2000 ms 27636 KB
#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;
int ile[LIM];
bool ok;
void DFS(int x) {
  ile[x]=1;
  for(auto i : V[x]) {
    DFS(i.nd);
    ile[x]+=ile[i.nd];
  }
}
void DFS2(int x) {
  for(int i=1; i<V[x].size(); ++i) if(V[x][i].st==V[x][i-1].st) ok=false;
  K.pb({ile[x], x});
  for(auto i : V[x]) DFS2(i.nd);
}
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;
}
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]));
  DFS(0);
  vector<int>ans(n);
  rep(i, n) {
    K.clear();
    ok=true;
    DFS2(i);
    sort(all(K));
    for(int j=1; j<K.size(); ++j) if(!zawiera(K[j-1].nd, K[j].nd)) ok=false;
    if(ok) ans[i]=1;
  }
  return ans;
}

Compilation message

beechtree.cpp: In function 'void DFS2(int)':
beechtree.cpp:21: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]
   21 |   for(int i=1; i<V[x].size(); ++i) if(V[x][i].st==V[x][i-1].st) ok=false;
      |                ~^~~~~~~~~~~~
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:28:3: note: in expansion of macro 'rep'
   28 |   rep(i, V[a].size()) {
      |   ^~~
beechtree.cpp:29: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]
   29 |     while(l<V[b].size() && V[b][l].st!=V[a][i].st) ++l;
      |           ~^~~~~~~~~~~~
beechtree.cpp:30: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]
   30 |     if(l==V[b].size()) return false;
      |        ~^~~~~~~~~~~~~
beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int j=1; j<K.size(); ++j) if(!zawiera(K[j-1].nd, K[j].nd)) ok=false;
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 1 ms 5732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 2 ms 5728 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 1 ms 5724 KB Output is correct
12 Correct 1 ms 5724 KB Output is correct
13 Correct 1 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 1 ms 5720 KB Output is correct
16 Correct 1 ms 5724 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 2 ms 5972 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
22 Correct 2 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 1 ms 5724 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 1 ms 5724 KB Output is correct
27 Correct 2 ms 5724 KB Output is correct
28 Correct 1 ms 5720 KB Output is correct
29 Correct 2 ms 5720 KB Output is correct
30 Correct 2 ms 5724 KB Output is correct
31 Correct 1 ms 5724 KB Output is correct
32 Correct 2 ms 5724 KB Output is correct
33 Correct 1 ms 5724 KB Output is correct
34 Correct 2 ms 5720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Execution timed out 2025 ms 27496 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 1 ms 5724 KB Output is correct
7 Correct 1 ms 5720 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 1 ms 5720 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 2 ms 5720 KB Output is correct
12 Correct 2 ms 5720 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 45 ms 10172 KB Output is correct
16 Correct 45 ms 10964 KB Output is correct
17 Correct 47 ms 11016 KB Output is correct
18 Correct 45 ms 11216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5728 KB Output is correct
5 Execution timed out 2025 ms 27496 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 1 ms 5732 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 1 ms 5724 KB Output is correct
7 Correct 1 ms 5724 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 2 ms 5728 KB Output is correct
12 Correct 1 ms 5724 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 1 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 1 ms 5724 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 1 ms 5720 KB Output is correct
19 Correct 1 ms 5724 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5972 KB Output is correct
22 Correct 2 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 2 ms 5724 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 2 ms 5724 KB Output is correct
27 Correct 1 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 1 ms 5724 KB Output is correct
30 Correct 2 ms 5724 KB Output is correct
31 Correct 1 ms 5720 KB Output is correct
32 Correct 2 ms 5720 KB Output is correct
33 Correct 2 ms 5724 KB Output is correct
34 Correct 1 ms 5724 KB Output is correct
35 Correct 2 ms 5724 KB Output is correct
36 Correct 1 ms 5724 KB Output is correct
37 Correct 2 ms 5720 KB Output is correct
38 Correct 2 ms 5724 KB Output is correct
39 Correct 1 ms 5724 KB Output is correct
40 Correct 2 ms 5724 KB Output is correct
41 Correct 2 ms 5724 KB Output is correct
42 Correct 1 ms 5724 KB Output is correct
43 Correct 1 ms 5724 KB Output is correct
44 Correct 1 ms 5720 KB Output is correct
45 Correct 2 ms 5724 KB Output is correct
46 Correct 1 ms 5720 KB Output is correct
47 Correct 2 ms 5724 KB Output is correct
48 Correct 2 ms 5720 KB Output is correct
49 Correct 2 ms 5724 KB Output is correct
50 Correct 2 ms 5724 KB Output is correct
51 Correct 2 ms 5616 KB Output is correct
52 Correct 2 ms 5720 KB Output is correct
53 Correct 6 ms 5720 KB Output is correct
54 Correct 2 ms 5976 KB Output is correct
55 Correct 2 ms 5724 KB Output is correct
56 Correct 2 ms 5720 KB Output is correct
57 Correct 2 ms 5720 KB Output is correct
58 Correct 3 ms 5724 KB Output is correct
59 Correct 1 ms 5724 KB Output is correct
60 Correct 1 ms 5720 KB Output is correct
61 Correct 2 ms 5724 KB Output is correct
62 Correct 2 ms 5724 KB Output is correct
63 Correct 2 ms 5724 KB Output is correct
64 Correct 2 ms 5720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5728 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 1 ms 5724 KB Output is correct
8 Correct 1 ms 5724 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 1 ms 5720 KB Output is correct
12 Correct 1 ms 5724 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5972 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 1 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
22 Correct 1 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 1 ms 5720 KB Output is correct
25 Correct 44 ms 5724 KB Output is correct
26 Correct 45 ms 5724 KB Output is correct
27 Correct 49 ms 5968 KB Output is correct
28 Correct 49 ms 5720 KB Output is correct
29 Correct 47 ms 5720 KB Output is correct
30 Correct 6 ms 5724 KB Output is correct
31 Correct 3 ms 5856 KB Output is correct
32 Correct 3 ms 5724 KB Output is correct
33 Correct 5 ms 5724 KB Output is correct
34 Correct 3 ms 5724 KB Output is correct
35 Correct 3 ms 5724 KB Output is correct
36 Correct 2 ms 5788 KB Output is correct
37 Correct 14 ms 5724 KB Output is correct
38 Correct 7 ms 5724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 1 ms 5732 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 1 ms 5724 KB Output is correct
7 Correct 1 ms 5724 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 2 ms 5728 KB Output is correct
12 Correct 1 ms 5724 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 1 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 1 ms 5724 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 1 ms 5720 KB Output is correct
19 Correct 1 ms 5724 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5972 KB Output is correct
22 Correct 2 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 2 ms 5724 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 2 ms 5724 KB Output is correct
27 Correct 1 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 1 ms 5724 KB Output is correct
30 Correct 2 ms 5724 KB Output is correct
31 Correct 1 ms 5720 KB Output is correct
32 Correct 2 ms 5720 KB Output is correct
33 Correct 2 ms 5724 KB Output is correct
34 Correct 1 ms 5724 KB Output is correct
35 Correct 2 ms 5724 KB Output is correct
36 Correct 1 ms 5724 KB Output is correct
37 Correct 2 ms 5720 KB Output is correct
38 Correct 2 ms 5720 KB Output is correct
39 Correct 2 ms 5724 KB Output is correct
40 Correct 2 ms 5724 KB Output is correct
41 Correct 2 ms 5616 KB Output is correct
42 Correct 2 ms 5724 KB Output is correct
43 Correct 1 ms 5724 KB Output is correct
44 Correct 2 ms 5724 KB Output is correct
45 Correct 2 ms 5724 KB Output is correct
46 Correct 1 ms 5724 KB Output is correct
47 Correct 1 ms 5724 KB Output is correct
48 Correct 1 ms 5720 KB Output is correct
49 Correct 2 ms 5724 KB Output is correct
50 Correct 1 ms 5720 KB Output is correct
51 Correct 2 ms 5724 KB Output is correct
52 Correct 2 ms 5720 KB Output is correct
53 Correct 2 ms 5720 KB Output is correct
54 Correct 2 ms 5724 KB Output is correct
55 Correct 2 ms 5724 KB Output is correct
56 Correct 2 ms 5720 KB Output is correct
57 Correct 6 ms 5720 KB Output is correct
58 Correct 2 ms 5976 KB Output is correct
59 Correct 2 ms 5724 KB Output is correct
60 Correct 2 ms 5720 KB Output is correct
61 Correct 2 ms 5720 KB Output is correct
62 Correct 3 ms 5724 KB Output is correct
63 Correct 1 ms 5724 KB Output is correct
64 Correct 1 ms 5720 KB Output is correct
65 Correct 2 ms 5724 KB Output is correct
66 Correct 2 ms 5724 KB Output is correct
67 Correct 2 ms 5724 KB Output is correct
68 Correct 2 ms 5720 KB Output is correct
69 Correct 44 ms 5724 KB Output is correct
70 Correct 45 ms 5724 KB Output is correct
71 Correct 49 ms 5968 KB Output is correct
72 Correct 49 ms 5720 KB Output is correct
73 Correct 47 ms 5720 KB Output is correct
74 Correct 6 ms 5724 KB Output is correct
75 Correct 3 ms 5856 KB Output is correct
76 Correct 3 ms 5724 KB Output is correct
77 Correct 5 ms 5724 KB Output is correct
78 Correct 3 ms 5724 KB Output is correct
79 Correct 3 ms 5724 KB Output is correct
80 Correct 2 ms 5788 KB Output is correct
81 Correct 14 ms 5724 KB Output is correct
82 Correct 7 ms 5724 KB Output is correct
83 Correct 46 ms 5940 KB Output is correct
84 Correct 46 ms 5724 KB Output is correct
85 Correct 46 ms 5724 KB Output is correct
86 Correct 62 ms 5724 KB Output is correct
87 Correct 13 ms 5724 KB Output is correct
88 Correct 3 ms 5724 KB Output is correct
89 Correct 17 ms 5724 KB Output is correct
90 Correct 5 ms 5724 KB Output is correct
91 Correct 3 ms 5724 KB Output is correct
92 Correct 4 ms 5724 KB Output is correct
93 Correct 7 ms 5980 KB Output is correct
94 Correct 2 ms 5724 KB Output is correct
95 Correct 2 ms 5724 KB Output is correct
96 Correct 2 ms 5848 KB Output is correct
97 Correct 22 ms 5724 KB Output is correct
98 Correct 7 ms 5724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5728 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 1 ms 5724 KB Output is correct
8 Correct 1 ms 5724 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 1 ms 5720 KB Output is correct
12 Correct 1 ms 5724 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5972 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 1 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
22 Correct 1 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 1 ms 5720 KB Output is correct
25 Correct 44 ms 5724 KB Output is correct
26 Correct 45 ms 5724 KB Output is correct
27 Correct 49 ms 5968 KB Output is correct
28 Correct 49 ms 5720 KB Output is correct
29 Correct 47 ms 5720 KB Output is correct
30 Correct 6 ms 5724 KB Output is correct
31 Correct 3 ms 5856 KB Output is correct
32 Correct 3 ms 5724 KB Output is correct
33 Correct 5 ms 5724 KB Output is correct
34 Correct 3 ms 5724 KB Output is correct
35 Correct 3 ms 5724 KB Output is correct
36 Correct 2 ms 5788 KB Output is correct
37 Correct 14 ms 5724 KB Output is correct
38 Correct 7 ms 5724 KB Output is correct
39 Execution timed out 2041 ms 27636 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 1 ms 5732 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 1 ms 5724 KB Output is correct
7 Correct 1 ms 5724 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 2 ms 5728 KB Output is correct
12 Correct 1 ms 5724 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 1 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 1 ms 5724 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 1 ms 5720 KB Output is correct
19 Correct 1 ms 5724 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5972 KB Output is correct
22 Correct 2 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 2 ms 5724 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 2 ms 5724 KB Output is correct
27 Correct 1 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 1 ms 5724 KB Output is correct
30 Correct 2 ms 5724 KB Output is correct
31 Correct 1 ms 5720 KB Output is correct
32 Correct 2 ms 5720 KB Output is correct
33 Correct 2 ms 5724 KB Output is correct
34 Correct 1 ms 5724 KB Output is correct
35 Correct 2 ms 5724 KB Output is correct
36 Correct 1 ms 5724 KB Output is correct
37 Correct 2 ms 5720 KB Output is correct
38 Execution timed out 2025 ms 27496 KB Time limit exceeded
39 Halted 0 ms 0 KB -