250909

lililllilillll·2025년 9월 8일

개발 일지

목록 보기
289/350

✅ 한 것들


  • 백준
  • 정글 퀴즈 복습
  • 펄어비스 필기 테스트 : 코테는 2/3솔, cs는 12문제 중 (아마) 1-4개 틀
    • 코테 볼 땐 브라우저 단축키 꺼두자. (ctrl+s 때문에 gpt 두 번이나 잠깐 열어버림)
    • 코테가 다들 개열받게 테케 조금만 주고 채점도 안 해주고 알아서 생각해보라는 식
      • 테케 맞고 로직 맞으면 끝이 아니라 예외 처리, 시간/공간 복잡도까지 문제라고 생각하는듯.
      • 범위 처리 신경써서 하고 문제 조건도 꼼꼼히 읽어서 반영해야 한다.
      • 예외 생각 안 했으면 말도 안되게 쉬운 1번부터 틀릴 뻔 했다.
      • 3번도 풀긴 풀었는데 예외 처리 부등호에 등호 하나 추가 안 해서 틀린 것 같음.


⚔️ 백준


바이러스

#include<iostream>
#include<vector>
#include<map>
#include<stack>
#include<queue>
using namespace std;
typedef map<int, vector<int>> mivi;

int dfs(int node, mivi& graph, vector<bool>& visit)
{
	if (visit[node]) return 0;
	visit[node] = true;
	int count = 1;
	for (int next : graph[node]) {
		count += dfs(next, graph, visit);
	}
	return count;
}

int main() {
	int n, c;
	cin >> n >> c;
	vector<bool> v = vector<bool>(n,false);
	mivi g;
	while (c--) {
		int s, a;
		cin >> s >> a;
		g[s-1].push_back(a-1);
		g[a - 1].push_back(s - 1);
	}
	int count = 0;

	// dfs stack ver.
	//v[0] = true;
	//stack<int> s; s.push(0);
	//while (!s.empty()) {
	//	int t = s.top(); s.pop();
	//	for (int next : g[t]) {
	//		if (v[next]) continue;
	//		s.push(next);
	//		v[next] = true;
	//		count++;
	//	}
	//}

	// dfs recur ver.
	//count = dfs(0, g, v);
	//count--; // 자기 자신 제외

	// bfs
	v[0] = true;
	queue<int> q; q.push(0);
	while (!q.empty()) {
		int f = q.front(); q.pop();
		for (int next : g[f]) {
			if (v[next]) continue;
			v[next] = true;
			q.push(next);
			count++;
		}
	}

	cout << count;
}

dfs bfs 연습

profile
너 정말 **핵심**을 찔렀어

0개의 댓글