Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 유니온 파인드
- 그래프
- 투 포인터
- 정렬
- 재귀
- XR Interaction Toolkit
- 유니티
- 백트래킹
- 브루트포스
- Unreal Engine 5
- 다이나믹 프로그래밍
- 수학
- 알고리즘
- 자료구조
- c++
- 시뮬레이션
- BFS
- 우선순위 큐
- 그리디 알고리즘
- Team Fortress 2
- 백준
- 다익스트라
- ue5
- 트리
- 구현
- VR
- 문자열
- 누적 합
- DFS
- 스택
Archives
- Today
- Total
1일1알
백준 14675번 단절점과 단절선 C++ 본문
https://www.acmicpc.net/problem/14675
14675번: 단절점과 단절선
프로그램의 입력은 표준 입력으로 받는다. 입력의 첫 줄에는 트리의 정점 개수 N이 주어진다. (2 ≤ N ≤ 100,000) 트리의 정점은 1번부터 n번까지 존재한다. 다음 줄부터 N-1개의 줄에 걸쳐 간선의 정
www.acmicpc.net
트리에서는 단절점과 단절선의 조건이 아래와 같다.
단절점 : 리프 노드가 아니면 전부 단절점이다.
단절선 : 모든 선이 단절선이다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n, q;
vector<vector<int>> tree;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
tree = vector<vector<int>>(n + 1, vector<int>());
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
tree[a].push_back(b);
tree[b].push_back(a);
}
cin >> q;
for (int i = 0; i < q; i++) {
int t, k;
cin >> t >> k;
bool isTrue = true;
if (t == 1) {
if (tree[k].size() == 1) isTrue = false;
}
if (isTrue) cout << "yes\n";
else cout << "no\n";
}
}
'알고리즘' 카테고리의 다른 글
백준 10972번 다음 순열 C++ (0) | 2023.05.28 |
---|---|
백준 19942번 다이어트 C++ (0) | 2023.05.27 |
백준 21938번 영상처리 C++ (0) | 2023.05.25 |
백준 15947번 아기 석환 뚜루루 뚜루 C++ (0) | 2023.05.22 |
백준 16938번 캠프 준비 C++ (0) | 2023.05.21 |