답안 #1047447

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047447 2024-08-07T13:10:59 Z Abito 참나무 (IOI23_beechtree) C++17
0 / 100
1 ms 8796 KB
#include "beechtree.h"
#include <bits/stdc++.h>
#define pb push_back
#define elif else if
#define ep insert
#define S second
#define F first
using namespace std;
const int N=2e5+5;
int a[N],c[N],p[N],n,mxd[N],dis[N],f[N];
vector<int> adj[N],s;
void getmxd(int x){
    if (x) dis[x]=dis[p[x]]+1;
    mxd[x]=dis[x];
    for (auto u:adj[x]){
        getmxd(u);
        mxd[x]=max(mxd[x],mxd[u]);
    }return;
}
void getsub(int x){
    s.pb(x);
    for (auto u:adj[x]) getsub(u);
    return;
}
vector<int> beechtree(int N, int M, vector<int> P, vector<int> C)
{
    n=N;
    vector<int> ans(n,0);
    for (int i=0;i<n;i++) p[i]=P[i],c[i]=C[i];
    for (int i=1;i<n;i++) adj[p[i]].pb(i);
    getmxd(0);
    int x=0;
    for (int i=0;i<n;i++){
        if (adj[i].empty()) ans[i]=1,x++;
        elif (mxd[i]-dis[i]==1){
            set<int> s;
            for (auto u:adj[i]) s.ep(c[u]);
            if (s.size()==adj[i].size()) ans[i]=1,x++;
        }
    }
    if (x!=n-1){
        return ans;
    }
    for (int i=0;i<n;i++) if (dis[i]==1) f[c[i]]++;
    set<int> s;
    for (int i=0;i<n;i++) if (dis[i]==2) s.ep(c[i]);
    bool ok=true,h=-1;
    for (auto u:s){
        if (h==-1) h=f[u];
        if (f[u]!=h) ok=0;
    }
    ans[0]=ok;
    return ans;
}

Compilation message

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:49:14: warning: comparison of constant '-1' with boolean expression is always false [-Wbool-compare]
   49 |         if (h==-1) h=f[u];
      |             ~^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 1 ms 8792 KB Output is correct
3 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -