(java)Pat刷题日记-1004 Counting Leaves (30 分)

一开始自己做的真的很乱,把题目搞错了

借鉴了一下别的大神,自己模仿着写了一遍
其实是一道考图的遍历的题目,用了DFS来做


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main{
	
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int id ,k ;
		int b;
		int [] record = new int [100];
		ArrayList list = new ArrayList();
		HashMap> map = new HashMap<>();
		for(int i = 0;i();
			for(int j = 0;j> map,int[]record,int node,int level,int height) {
	ArrayList list = new ArrayList();
	list = map.get(node);
	if(list ==null)
	{
		record[level]++;
		return height;
	}
	for(int i = 0;i

你可能感兴趣的:((java)Pat刷题日记-1004 Counting Leaves (30 分))