京东笔试 什么是多部完全图
发布于 2018-09-09 21:36 2567 次浏览 0 赞 来自 我要提问  

RT 大神们能不能告诉我什么是“完全多部图 ”

4 条回复

google "complete multipartite graph"

2018-09-09 21:42

/*

直接 ac 100%, 不需要 bsf, dfs ,直接两个for循环就可以

*/


import java.util.*;


public class Main {


    public static class Node{

        public int value;

        public ArrayList<Node> nexts;

        public boolean pass;


        public Node(int value){

            this.value = value;

            nexts = new ArrayList<>();

            pass = false;

        }

    }


    public static void process(Scanner in){

        int n = in.nextInt();

        int m = in.nextInt();


        HashMap<Integer, Node> map = new HashMap<>();

        for(int i = 0; i < n; i++){

            map.put(i+1, new Node(i+1));

        }


        for(int i = 0; i < m; i++){

            int f = in.nextInt();

            int s = in.nextInt();

            Node nf = map.get(f);

            Node ns = map.get(s);

            nf.nexts.add(ns);

            ns.nexts.add(nf);

        }


        Node n1 = map.get(1);

        map.remove(1);

        List<Node> xl = n1.nexts;

        List<Node> nxl = new ArrayList<>();


        for (Map.Entry<Integer, Node> entry : map.entrySet()) {

            if(!xl.contains(entry.getValue())){

                nxl.add(entry.getValue());

            }

        }


        boolean pan = false;

        for(Node node : nxl){

            for(Node node1: xl){

                if(!node.nexts.contains(node1)){

                    pan = true;

                    break;

                }

            }

        }

        if(pan){

            System.out.println("No");

        }else{

            System.out.println("Yes");

        }

    }


    public static void main(String[] args){


        Scanner in = new Scanner(System.in);


        int n = in.nextInt();

        for(int i = 0; i < n; i++){

            process(in);

        }

    }

}


2018-09-09 22:02

二楼大佬,我想和您交流一下这道题,下面这个case,请问是完全多部图还是不是?

2018-09-10 12:29
coder_9HXMN7YT 回复 coder_M899F3XJ

感谢您的解答,我有点问题,写在三楼了,希望可以交流一下

2018-09-10 12:29
添加回复
回到顶部