답안 #1008807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1008807 2024-06-26T19:57:50 Z aaaaaarroz 참나무 (IOI23_beechtree) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
vector<int>padre;
bool menor_padre(int i, int j){
    return padre[i]<padre[j];
}
vector<int> beechtree(int n, int m, vector<int>P, vector<int>C){
    vector<vector<int>>graph(n,vector<int>());
    padre=P;
    for(int i=1;i<n;i++){
        graph[P[i]].push_back(i);
    }
    vector<int>ans(n,0);
    for(int i=0;i<n;i++){
        vector<int>sub;
        queue<int>cola;
        cola.push(i);
        while(!cola.empty()){
            int nodo=cola.front(); 
            cola.pop();
            sub.push_back(nodo);
            for(int vecino:graph[nodo]){
                cola.push(vecino);
            } 
        }
        if(sub.size()==1){
			ans[i]=1;
			continue;
		}
        sort(sub.begin()+1,sub.end(),menor_padre);
        bool bien=true;
        map<int,int>repeticiones;
        for(int j=1;j<sub.size();j++){
                if(repeticiones.find(C[sub[j]])==repeticiones.end()){
                repeticiones[C[sub[j]]]=0;
                }
            if(sub[repeticiones[C[sub[j]]]]!=P[sub[j]]){
                bien=false;
                break;
            }
            repeticiones[C[sub[j]]]++;
        }
        if(bien){
            ans[i]=1;
        }
    }
    return {ans};
}
int main(){
    int N, M;
    assert(2 == scanf("%d %d", &N, &M));
    vector<int> P(N);
    for (int i = 0; i < N; ++i)
        assert(1 == scanf("%d", &P[i]));
    vector<int> C(N);
    for (int i = 0; i < N; ++i)
        assert(1 == scanf("%d", &C[i]));
 
    fclose(stdin);
    vector<int> res = beechtree(N, M, P, C);
    int n = res.size();
    for (int i = 0; i < n; ++i)
    {
        if (i > 0)
            printf(" ");
        printf("%d", res[i]);
    }
    printf("\n");
    fclose(stdout);
    return 0;
}

Compilation message

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:33:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for(int j=1;j<sub.size();j++){
      |                     ~^~~~~~~~~~~
/usr/bin/ld: /tmp/ccg9iYEw.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccb3EACA.o:beechtree.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status