Rezultati

Up. imeNalogaJezikRezultatČas oddaje
pridnerozice-2018 Nič nas ne sme presenetiti! Java 0/100Napaka med izvajanjem / ob izhodu (RTE) 19. apr '18 @ 17:50

Test Točke Porabljen spomin Porabljen čas Status
#1 12/12 31,785 MiB 0,000 s OK
#2 12/12 78,547 MiB 1,518 s OK
#3 12/12 33,148 MiB 0,000 s OK
#4 0/12 161,793 MiB 0,000 s Prekoračen spomin
Stderr:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Nic.main(source.java:9)
#5 13/13 38,359 MiB 0,000 s OK
#6 0/13 158,836 MiB 0,000 s Prekoračen spomin
Stderr:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Nic.main(source.java:9)
#7 0/13 161,855 MiB 0,000 s Prekoračen spomin
Stderr:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Nic.main(source.java:9)
#8 0/13 160,660 MiB 0,000 s Prekoračen spomin
Stderr:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Nic.main(source.java:9)

Ocenjevani program (Nic.java):
import java.util.*;

class Nic{
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int[][] array = new int[n + 1][n + 1];

        for(int i = 0; i < n - 1; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();

            array[a][b] = 1;
            array[b][a] = 1;
        }
        for(int i = 0; i < q; i++) {
            int stMest = sc.nextInt();
            int[][] mesta = new int[stMest][2];
            for(int j = 0; j < stMest; j++) {
                mesta[j][0] = sc.nextInt();
            }
            mesta[0][1] = 1;
            List<Integer> vrsta = new ArrayList<Integer>();
            vrsta.add(mesta[0][0]);
            int st = 1;
            while (!vrsta.isEmpty()) {
                int trenutnoMesto = vrsta.get(0);
                vrsta.remove(0);
                for(int j = 0; j < stMest; j++) {
                    int mesto2 = mesta[j][0];
                    if(array[trenutnoMesto][mesto2] == 1) {
                        if(mesta[j][1] != 1) {
                            vrsta.add(mesta[j][0]);
                            mesta[j][1] = 1;
                            st++;
                        }
                    }
                }
            }
            if(st == stMest) System.out.println("ALAAAARHM");
            else System.out.println("NASLEDNJI");
        }




    }
}