1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.ArrayList;
import java.util.Scanner;


public class mis {

	public static void main(String[] args) {
		Scanner wejscie = new Scanner(System.in);
		int m, n, d;
		n = wejscie.nextInt();
		m = wejscie.nextInt();
		d = wejscie.nextInt();
		ArrayList<ArrayList<Integer>> listOLists = new ArrayList<ArrayList<Integer>>();
		for(int i=0; i<n; i++)
			{
			ArrayList<Integer> singleList = new ArrayList<Integer>();
			listOLists.add(singleList);
			}
		int [][]t = new int[n][2];
		int [] wystapienia = new int [n];
		for(int x=0; x<n; x++)
		{
			
			for(int y=0; y<2; y++)
			{
				t[x][y]=wejscie.nextInt();
				if(y==1)listOLists.get(x).add(t[x][y]);
				wystapienia[t[x][y]-1]++;
			}
		}
		int liczbaZmian=1;
		while(liczbaZmian!=0)
		{
			liczbaZmian=0;
			for(int i=0; i<n; i++)
			{
				if(wystapienia[i]<d && wystapienia[i]!=-1)
				{
					wystapienia[i]=-1;
					for(int z=0; z<listOLists.get(i).size();z++)
					{
						wystapienia[listOLists.get(i).get(z)-1]--;
					}
					liczbaZmian++;
					
				}
			}
		}
		for(int i=0; i<n; i++)if(wystapienia[i]!=-1)System.out.println(i+1);
		wejscie.close();
	}

}