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; } }

相关推荐

不愿透露姓名的神秘牛友
昨天 17:16
科大讯飞 算法工程师 28.0k*14.0, 百分之三十是绩效,惯例只发0.9
点赞 评论 收藏
分享
牛客网
牛客企业服务