SW练习_ADV_凭运气找宝石_BFS

package info.frady.adv;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.*;

public class BaoShiYunqi_ {
    static boolean [] rukou;
    static int[] depth;
    static Nodeadv0808[] nodes;
    public static void main(String[] args) throws Exception{
        //System.setIn(new FileInputStream("C:\\Users\\86153\\Desktop\\SW\\凭运气找宝石\\test_input.txt"));
        //System.setIn(new FileInputStream("C:\\Users\\86153\\Desktop\\SW\\凭运气找宝石\\sample_input.txt"));
        long statTime=System.currentTimeMillis();
        System.setIn(new FileInputStream("C:\\Users\\86153\\Desktop\\SW\\凭运气找宝石\\eval_input.txt"));
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(reader.readLine());
        int T=Integer.parseInt(st.nextToken());
        for (int zz = 0; zz  list=new LinkedList();
        list.add(startIndex);
        nodes[startIndex].vis=true;

        while (!list.isEmpty()){

            Integer start=list.pop();
            //System.out.printf("pop[viste] %d\n",start);
            for (Integer sonIndex:nodes[start].sonList
                 ) {
                if(!nodes[sonIndex].vis){
                    nodes[sonIndex].vis=true;
                    depth[sonIndex]=depth[start]+1;
                    list.add(sonIndex);
                }

            }
        }

        int minDep=Integer.MAX_VALUE;
        int minIndex=0;
        for (Nodeadv0808 node:nodes) {
            if(rukou[node.index] ){
                if(depth[node.index] sonList;
    public Nodeadv0808(int index){
        this.index=index;
        this.sonList=new ArrayList<>();
        vis=false;
        //this.depth=0;
    }
}

 

你可能感兴趣的:(算法)