1) 1260번
import java.io.*;
import java.util.*;
public class Main {
//함수에서 사용할 변수들
static int[][] check; //간선 연결상태
static boolean[] checked; //확인 여부
static int n; //정점개수
static int m; //간선개수
static int start; //시작정점
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
start = sc.nextInt();
check = new int[1001][1001]; //좌표를 그대로 받아들이기 위해 +1해서 선언
checked = new boolean[1001]; //초기값 False
//간선 연결상태 저장
for(int i = 0; i < m; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
check[x][y] = check[y][x] = 1;
}
dfs(start); //dfs호출
checked = new boolean[1001]; //확인상태 초기화
System.out.println(); //줄바꿈
bfs(); //bfs호출
}
//시작점을 변수로 받아 확인, 출력 후 다음 연결점을 찾아 시작점을 변경하여 재호출
public static void dfs(int i) {
checked[i] = true;
System.out.print(i + " ");
for(int j = 1; j <= n; j++) {
if(check[i][j] == 1 && checked[j] == false) {
dfs(j);
}
}
}
public static void bfs() {
Queue<Integer> queue = new LinkedList<Integer>();
queue.offer(start); //시작점도 Queue에 넣어야 함
checked[start] = true;
System.out.print(start + " ");
//Queue가 빌 때까지 반복. 방문 정점은 확인, 출력 후 Queue에 넣어 순서대로 확인
while(!queue.isEmpty()) {
int temp = queue.poll();
for(int j = 1; j <= n; j++) {
if(check[temp][j] == 1 && checked[j] == false) {
queue.offer(j);
checked[j] = true;
System.out.print(j + " ");
}
}
}
}
}
2) 2178번
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
static int[][] map;
static int n;
static int m;
static boolean[][] visited;
static int[] dx = { -1, 1, 0, 0 }; //x방향배열-상하
static int[] dy = { 0, 0, -1, 1 }; //y방향배열-좌우
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
map = new int[n][m];
for(int i=0; i<n; i++) {
String s = br.readLine();
for(int j=0; j<m; j++) {
map[i][j] = s.charAt(j) - '0';
}
}
visited = new boolean[n][m];
visited[0][0] = true;
bfs(0, 0);
System.out.println(map[n-1][m-1]);
}
public static void bfs(int x, int y) {
Queue<int[]> q = new LinkedList<>();
q.add(new int[] {x,y});
while(!q.isEmpty()) {
int now[] = q.poll();
int nowX = now[0];
int nowY = now[1];
for(int i=0; i<4; i++) {
int nextX = nowX + dx[i];
int nextY = nowY + dy[i];
if (nextX < 0 || nextY < 0 || nextX >= n || nextY >= m)
continue;
if (visited[nextX][nextY] || map[nextX][nextY] == 0)
continue;
q.add(new int[] {nextX, nextY});
map[nextX][nextY] = map[nowX][nowY] + 1;
visited[nextX][nextY] = true;
}
}
}
}
3) 2217번
def solution():
answer = 0
arr.sort(reverse=True)
for i in range(N):
arr[i] = arr[i] * (i + 1)
return max(arr)
N = int(input())
arr = []
for _ in range(N):
arr.append(int(input()))
print(solution())