답안 #1047431

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047431 2024-08-07T12:57:25 Z Abito 참나무 (IOI23_beechtree) C++17
8 / 100
65 ms 28244 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];
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);
    for (int i=0;i<n;i++){
        if (adj[i].empty()) ans[i]=1;
        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;
        }
    }
    for (int i=0;i<n;i++){
        s.clear();
        if (mxd[i]-dis[i]!=2) continue;
        getsub(i);
        set<int> par;
        bool ok=true;
        //for (auto u:s) cout<<u<<' ';cout<<endl;
        for (int i=1;i<s.size();i++) par.ep(p[s[i]]);
        if (par.size()>2) continue;
        map<int,vector<int>> mp;
        for (int i=1;i<s.size();i++) mp[c[s[i]]].pb(s[i]);
        for (auto u:mp){
            if (u.S.size()==1){
                if (p[u.S[0]]==i) continue;
                ok=false;
                break;
            }
            if (u.S.size()==2){
                if (p[u.S[0]]==p[u.S[1]]){
                    ok=false;
                    break;
                }
            }
        }ans[i]=ok;
    }
    return ans;
}

Compilation message

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for (int i=1;i<s.size();i++) par.ep(p[s[i]]);
      |                      ~^~~~~~~~~
beechtree.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for (int i=1;i<s.size();i++) mp[c[s[i]]].pb(s[i]);
      |                      ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Incorrect 1 ms 8796 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 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 8792 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 8792 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 8796 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8796 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
10 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 Correct 1 ms 8792 KB Output is correct
4 Correct 1 ms 8676 KB Output is correct
5 Correct 45 ms 28244 KB Output is correct
6 Correct 46 ms 28244 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 50 ms 17784 KB Output is correct
12 Correct 65 ms 16680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Incorrect 1 ms 8796 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 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 Correct 1 ms 8792 KB Output is correct
4 Correct 1 ms 8676 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 1 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 1 ms 8796 KB Output is correct
13 Correct 1 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 1 ms 8796 KB Output is correct
16 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Incorrect 1 ms 8796 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 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 Correct 1 ms 8792 KB Output is correct
4 Correct 1 ms 8676 KB Output is correct
5 Correct 1 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8796 KB Output is correct
9 Correct 1 ms 8796 KB Output is correct
10 Correct 1 ms 8796 KB Output is correct
11 Correct 1 ms 8796 KB Output is correct
12 Correct 1 ms 8796 KB Output is correct
13 Correct 1 ms 8796 KB Output is correct
14 Correct 1 ms 8796 KB Output is correct
15 Correct 1 ms 8796 KB Output is correct
16 Incorrect 1 ms 8796 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Incorrect 1 ms 8796 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -