public class Main { static long[]w; static List<Integer>[]children; public static boolean isTSN(long num) { long n = (long) Math.sqrt(num); return n * n == num; } public static int[]dfs(int cur) { if (children[cur] == null) return new int[]{0, 0}; int[]ret = new int[]{0, 0}; int bonus = 0; for (int child : children[cur]) { int[]childRes = dfs(child); boolean flag = isTSN(w[cur] * w[child]); bonus = Math.max(bonus, childRes[1] + (flag ? 2 : 0) - childRes[0]); ret[1] += childRes[0]; } ret[0] = ret[1] + bonus; return ret; } }

相关推荐

用微笑面对困难:不是你千万别小看这家公司,他们的预估市值成倍上涨,三次在报告看见这个公司了,总之如果是给股权的话可以试试,未来没准真能发家致富哈哈哈哈
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务