개발자 톡

연습문제 톡 지우는 소수를 좋아해

지우는 소수를 좋아해 반례 부탁드립니다.

등록일
2021-10-12 21:25:13
조회수
888
작성자
dongwoni3

import java.util.*;
import java.io.*;


public class Main
{
    static int N, M, totalMax=1000000000;
    public static void main(String args[])
    {
        int from, to, weight;
        Map map = new HashMap<>();

        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();

        for(int i=0;ito){
                int temp=from;
                from=to;
                to=temp;
            }
            if(map.containsKey(from)){
                Map subMap = map.get(from);
                if(!subMap.containsKey(to)) subMap.put(to,weight);
                else if(subMap.get(to) subMap = new HashMap<>();
                subMap.put(to, weight);
                map.put(from, subMap);
            }
        }
        backTrack(map, 1, 1);
        System.out.println(getMaxPrimeNum(totalMax));
    }

    public static void backTrack(Map map, int from, int max){
        if(from==N){
            if(max subMap= map.get(from);
        for(int to:subMap.keySet()){
            int weight = subMap.get(to);
            if(weight>totalMax) continue;
            if(weight


import java.util.*;
import java.io.*;


public class Main
{
    static int N, M, totalMax=1000000000;
    public static void main(String args[])
    {
        int from, to, weight;
        Map map = new HashMap<>();

        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();

        for(int i=0;ito){
                int temp=from;
                from=to;
                to=temp;
            }
            if(map.containsKey(from)){
                Map subMap = map.get(from);
                if(!subMap.containsKey(to)) subMap.put(to,weight);
                else if(subMap.get(to)>weight) subMap.put(to,weight);
            }
            else{
                Map subMap = new HashMap<>();
                subMap.put(to, weight);
                map.put(from, subMap);
            }
        }
        backTrack(map, 1, 1);
        System.out.println(getMaxPrimeNum(totalMax));
        //System.out.println(totalMax);
    }

    public static void backTrack(Map map, int from, int max){
        if(from==N){
            if(max subMap= map.get(from);
        for(int to:subMap.keySet()){
            int weight = subMap.get(to);
            //System.out.println("from"+from+"to"+to+"weight"+weight+"totalMax"+totalMax+"max"+max);
            if(weight>totalMax) continue;
            if(weight


#지우는_소수를_좋아해
#java

이 카테고리의 톡 더보기