[백준/Java] 10813 : 공 바꾸기

SEOP·2023년 6월 11일
0
post-custom-banner

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {

        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] STR1 =  br.readLine().split(" ");
        int N = Integer.parseInt(STR1[0]);
        int M = Integer.parseInt(STR1[1]);

        List list = new ArrayList();
        for(int i = 0 ; i < N ; i++){
            list.add(i+1);
        }

        for(int j = 0 ; j < M ; j++){
            String[] list2 = br.readLine().split(" ");
            int c = Integer.parseInt(list2[0]) -1;
            int d = Integer.parseInt(list2[1]) -1;

            int temp = (Integer) list.get(c);

            list.set(c,list.get(d));
            list.set(d,temp);
        }

        for(int k = 0 ; k < N ; k++){
            bw.write(list.get(k) + " ");
        }

        bw.flush();
        bw.close();

    }
}
profile
응애 나 애기 개발자
post-custom-banner

0개의 댓글