栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3516 Tree of Three

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3516 Tree of Three

#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#include<string>#include<map>#include<set>#include<iostream>#include<vector>#include<queue>using namespace std;#define sz(v) ((int)(v).size())#define rep(i, n) for (int i = 0; i < (n); ++i)#define repf(i, a, b) for (int i = (a); i <= (b); ++i)#define repd(i, a, b) for (int i = (a); i >= (b); --i)#define clr(x) memset(x,0,sizeof(x))#define clrs( x , y ) memset(x,y,sizeof(x))typedef long long lint;const int maxint = -1u>>1;const double esp = 1e-8;const int maxn = 10000+ 10;int v[maxn];int n, m;vector<int> b[maxn], f[maxn], e[maxn];void gao(int w){ b[w].clear(); b[w].push_back(v[w]); f[w].clear(); rep(i, sz(e[w])){ int j = e[w][i]; gao(j); rep(k, sz(f[j])) b[w].push_back(f[j][k]); } sort(b[w].begin(), b[w].end()); reverse(b[w].begin(), b[w].end()); rep(i, min(sz(b[w]), 3)){ f[w].push_back(b[w][i]); }}void add(int x, int y){ e[x].push_back(y);}int main(){ while(scanf("%d", &n) != EOF){ scanf("%d", &v[0]); rep(i, n) e[i].clear(); repf(i, 1, n - 1){ int x, y; scanf("%d%d", &x, &v[i]); add(x, i); } gao(0); scanf("%d", &m); rep(i, m){ int x; scanf("%d", &x); if(sz(f[x]) < 3 ) printf("-1n"); else printf("%d %d %dn", f[x][0], f[x][1], f[x][2]); } } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/377291.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号