# 11356: 【原1356】最大孩子

### 题目描述

author: Kainan Wang 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1356

## Output Format

k为被询问的节点的孩子中号码最大的号码。

3 2
0 1
1 2
3
0
1
2

-1
0
1

## WashSwang's solution

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int x,y,n,r,q,num=1,last[300000],to[300000],ne[300000],maxson[300000];
bool vis[300000];
to[num]=v;
ne[num]=last[u];
last[u]=num;
num++;
}
void find(int x){
vis[x]=true;
for (int i=last[x];i;i=ne[i])
if (!vis[to[i]]){
find(to[i]);
maxson[x]=max(maxson[x],to[i]);
}
}
int main() {
memset(maxson,-1,sizeof(maxson));
scanf("%d%d",&n,&r);
for (int i=0;i<n-1;++i){
scanf("%d%d",&x,&y);
}
find(r);
scanf("%d",&q);
for (int i=0;i<q;++i)
{
scanf("%d",&x);
printf("%d\n",maxson[x]);
}
return 0;
}

## yyong119's solution

#include <cstdio>
#include <vector>
#define MAX_N 100010
#define max(x, y) ((x) > (y) ? (x) : (y))
using namespace std;
struct Node {
int max_child_id;
vector<int> child_id;
}tree[MAX_N];
int n, root, q;
bool vis[MAX_N];
char ch = getchar(); int res = 0;
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9')
res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
return res;
}
void build_tree(int x) {
for (register int i = 0; i < link_id[x].size(); ++i)
}
int cur_max = -1;
for (register int i = 0; i < tree[x].child_id.size(); ++i) {
// max of the adjacent child
cur_max = max(cur_max, tree[x].child_id[i]);
// sb题目,孩子指直接相连的子节点
// max of children of the adjacent child
// cur_max = max(cur_max, tree[tree[x].child_id[i]].max_child_id);
}
tree[x].max_child_id = cur_max;
}
int main() {
for (register int i = 1; i < n; ++i) {