#include<bits/stdc++.h>
using namespace std;
struct node
{
int pre, nxt, key;
node(int _key = 0, int _pre = 0, int _nxt = 0)
{
pre = _pre;
key = _key;
nxt = _nxt;
}
};
node s[100005];
int n, m, tot = 0, index[100005] = { 0 };
void ins_back(int x, int y)
{
int now = index[x];
s[++tot] = node(y, now, s[now].nxt);
s[s[now].nxt].pre = tot;
s[now].nxt = tot;
index[y] = tot;
}
void ins_front(int x, int y)
{
int now = index[x];
s[++tot] = node(y, s[now].pre, now);
s[s[now].pre].nxt = tot;
s[now].pre = tot;
index[y] = tot;
}
void del(int x)
{
int now = index[x];
int le = s[now].pre, rt = s[now].nxt;
s[le].nxt = rt;
s[rt].pre = le;
index[x] = 0;
}
int main()
{
int x, k, p, now;
cin >> n;
s[0] = node();
ins_back(0, 1);
for (int i = 2; i <= n; i++)
{
cin >> k >> p;
p ? ins_back(k, i) : ins_front(k, i);
}
cin >> m;
for (int i = 1; i <= m; i++)
{
cin >> x;
if (index[x])del(x);
}
now = s[0].nxt;
while (now)
{
cout << s[now].key << " ";
now = s[now].nxt;
}
}
玄关。
洛谷编译不过,本地测样例过了。
洛谷编译信息:
/tmp/compiler_c9dfke6u/src:16:32: 错误:‘int index [100005]’ redeclared as different kind of entity
16 | int n, m, tot = 0, index[100005];
| ^
In file included from /nix/store/x8lqlydsxbrwvf6p7v18gws8kn1xl37f-glibc-2.38-23-dev/include/string.h:462,
from /nix/store/al0w33yvyzkjm86ndpf42knjfymfisph-luogu-gcc-13.2.0/include/c++/13.2.0/cstring:42,
from /nix/store/al0w33yvyzkjm86ndpf42knjfymfisph-luogu-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/stdc++.h:121,
from /tmp/compiler_c9dfke6u/src:1:
/nix/store/x8lqlydsxbrwvf6p7v18gws8kn1xl37f-glibc-2.38-23-dev/include/strings.h:61:1: 附注:previous declaration ‘const char* index(const char*, int)’
61 | index (const char *__s, int __c) __THROW
| ^~~~~
/tmp/compiler_c9dfke6u/src: In function ‘void ins_back(int, int)’:
/tmp/compiler_c9dfke6u/src:19:24: 错误:‘<未解决的重载函数类型>[int]’用作数组下标类型无效
19 | int now = index[x];
| ^
/tmp/compiler_c9dfke6u/src:23:14: 错误:‘<未解决的重载函数类型>[int]’用作数组下标类型无效
23 | index[y] = tot;
| ^
/tmp/compiler_c9dfke6u/src: In function ‘void ins_front(int, int)’:
/tmp/compiler_c9dfke6u/src:27:24: 错误:‘<未解决的重载函数类型>[int]’用作数组下标类型无效
27 | int now = index[x];
| ^
/tmp/compiler_c9dfke6u/src:31:14: 错误:‘<未解决的重载函数类型>[int]’用作数组下标类型无效
31 | index[y] = tot;
| ^
/tmp/compiler_c9dfke6u/src: In function ‘void del(int)’:
/tmp/compiler_c9dfke6u/src:35:24: 错误:‘<未解决的重载函数类型>[int]’用作数组下标类型无效
35 | int now = index[x];
| ^
/tmp/compiler_c9dfke6u/src:39:14: 错误:‘<未解决的重载函数类型>[int]’用作数组下标类型无效
39 | index[x] = 0;
| ^
/tmp/compiler_c9dfke6u/src: In function ‘int main()’:
/tmp/compiler_c9dfke6u/src:57:26: 错误:‘<未解决的重载函数类型>[int]’用作数组下标类型无效
57 | if (index[x])del(x);
| ^
怎么办?
大佬救救!