[백준] 1707 이분 그래프
2021. 2. 20. 20:26
Problem set
1707번: 이분 그래프 입력은 여러 개의 테스트 케이스로 구성되어 있는데, 첫째 줄에 테스트 케이스의 개수 K(2≤K≤5)가 주어진다. 각 테스트 케이스의 첫째 줄에는 그래프의 정점의 개수 V(1≤V≤20,000)와 간선의 개수 www.acmicpc.net #include #include #include #include #include using namespace std; vector a[20001]; int color[20001]; void dfs(int node, int c) { color[node] = c; for (int i=0; i
[백준] 11724 연결 요소의 개수
2021. 2. 20. 20:25
Problem set
11724번: 연결 요소의 개수 첫째 줄에 정점의 개수 N과 간선의 개수 M이 주어진다. (1 ≤ N ≤ 1,000, 0 ≤ M ≤ N×(N-1)/2) 둘째 줄부터 M개의 줄에 간선의 양 끝점 u와 v가 주어진다. (1 ≤ u, v ≤ N, u ≠ v) 같은 간선은 한 번만 주 www.acmicpc.net #include #include using namespace std; vector a[1001]; bool check[1001]; void dfs(int node) { check[node] = true; for (int i=0; i
[백준] 1260 DFS와 BFS
2021. 2. 20. 20:24
Problem set
1260번: DFS와 BFS 첫째 줄에 정점의 개수 N(1 ≤ N ≤ 1,000), 간선의 개수 M(1 ≤ M ≤ 10,000), 탐색을 시작할 정점의 번호 V가 주어진다. 다음 M개의 줄에는 간선이 연결하는 두 정점의 번호가 주어진다. 어떤 두 정점 사 www.acmicpc.net // 인접리스트 #include #include #include #include #include using namespace std; vector a[1001]; bool check[1001]; void dfs(int node) { check[node] = true; printf("%d ",node); for (int i=0; i
[백준] 13023 ABCDE
2021. 2. 20. 20:20
Problem set
13023번: ABCDE 문제의 조건에 맞는 A, B, C, D, E가 존재하면 1을 없으면 0을 출력한다. www.acmicpc.net #include #include #include using namespace std; bool a[2000][2000]; vector g[2000]; vector edges; int main() { int n, m; cin >> n >> m; for (int i=0; i> from >> to; edges.push_back({from, to}); edges.push_back({to, from}); a[from][to] = a[to][from] = true; g[from].push_back(to); g[to].push_back(from); } m *= 2; for (int..
[백준] 14391 종이 조각
2021. 2. 20. 20:18
Problem set
14391번: 종이 조각 영선이는 숫자가 쓰여 있는 직사각형 종이를 가지고 있다. 종이는 1×1 크기의 정사각형 칸으로 나누어져 있고, 숫자는 각 칸에 하나씩 쓰여 있다. 행은 위에서부터 아래까지 번호가 매겨져 있고, www.acmicpc.net #include #include using namespace std; int a[4][4]; int main() { int n, m; scanf("%d %d",&n,&m); for (int i=0; i
[백준] 1182 부분수열의 합
2021. 2. 20. 20:14
Problem set
1182번: 부분수열의 합 첫째 줄에 정수의 개수를 나타내는 N과 정수 S가 주어진다. (1 ≤ N ≤ 20, |S| ≤ 1,000,000) 둘째 줄에 N개의 정수가 빈 칸을 사이에 두고 주어진다. 주어지는 정수의 절댓값은 100,000을 넘지 않는다. www.acmicpc.net #include using namespace std; int a[20]; int main() { int n,s; cin >> n >> s; for (int i=0; i> a[i]; } int ans = 0; for (int i=1; i
[백준] 11723 집합
2021. 2. 20. 20:13
Problem set
11723번: 집합 첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다. www.acmicpc.net #include #include using namespace std; char b[111]; int main() { int n = 20; int m; scanf("%d",&m); int s = 0; int x; while (m--) { scanf("%s",b); if (!strcmp(b,"add")) { scanf("%d",&x); x--; s = (s | (1
[백준] 1248 맞춰봐
2021. 2. 20. 20:11
Problem set
1248번: 맞춰봐 규현이는 멍청하다. 왜냐하면, 1~10까지 수 밖에 모르기 때문이다. 어느 날 규현이 옆을 지나가던 태석이가 규현이를 보고 이렇게 외쳤다. "빵빵!!" 규현이는 "아하!" 하면서 세상에는 빵이란 수도 www.acmicpc.net #include #include using namespace std; int n; int sign[10][10]; int ans[10]; bool ok() { for (int i=0; i n; string s; cin >> s; int cnt = 0; for (int i=0; i