답안 #1031570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031570 2024-07-23T01:02:47 Z aaaaaarroz 참나무 (IOI23_beechtree) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> beechtree(int n, int m, vector<int> P, vector<int> C) {
    vector<vector<int>> graph(n);
    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> subtree;
        stack<int> s;
        s.push(i);
        while (!s.empty()) {
            int node = s.top(); s.pop();
            subtree.push_back(node);
            for (int neighbor : graph[node]) {
                s.push(neighbor);
            }
        }
        sort(subtree.begin() + 1, subtree.end(), [&](int a, int b) {
            if (C[a] != C[b]) {
                return C[a] < C[b];
            }
            return a > b;
        });
        bool is_bonito = true;
        for (int j = 1; j < subtree.size(); ++j) {
            if (P[subtree[j]] != subtree[j - 1]) {
                is_bonito = false;
                break;
            }
        }
        ans[i] = is_bonito ? 1 : 0;
    }
    return ans;
}

Compilation message

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:27:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for (int j = 1; j < subtree.size(); ++j) {
      |                         ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 2nd token, expected: '1', found: '0'
3 Halted 0 ms 0 KB -