团队题,全WA求条
  • 板块题目总版
  • 楼主yxszcxl
  • 当前回复1
  • 已保存回复1
  • 发布时间2025/1/21 22:08
  • 上次更新2025/1/22 09:30:05
查看原帖
团队题,全WA求条
1319065
yxszcxl楼主2025/1/21 22:08

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int n;
int a[N];
inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        x = x * 10 + ch - '0', ch = getchar();
    return x * f;
}

void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
    return;
}
struct
{
    int parent;
    int Left_child;
    int Right_child;
} Binary_Tree[N];
int main()
{
    n = read();
    for (int i = 1; i <= n; i++)
    {
        Binary_Tree[i].parent = read();
        if (Binary_Tree[Binary_Tree[i].parent].Left_child == 0)
            Binary_Tree[Binary_Tree[i].parent].Left_child = i;
        else
            Binary_Tree[Binary_Tree[i].parent].Right_child = i;
    }
    for (int i = 1; i <= n; i++)
    {
        if (Binary_Tree[i].Left_child)
        {
            write(Binary_Tree[i].Left_child);
            putchar(' ');
        }
        else
        {
            putchar('-1 ');
        }
        if (Binary_Tree[i].Right_child)
        {
            write(Binary_Tree[i].Right_child);
            putchar(' ');
        }
        else
        {
            putchar('-1 ');
        }
        putchar('\n');
    }
    return 0;
}
2025/1/21 22:08
加载中...