Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14-bomik0221 #57

Merged
merged 2 commits into from
Feb 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions bomik0221/μœ„μƒμ •λ ¬/240215.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
ο»Ώ#include <iostream>
#include <vector>
#include <queue>

int main() {
int N, M;
std::cin >> N >> M;

std::vector<std::vector<int>> graph(N + 1, std::vector<int>(0, 0));
std::vector<int> indegree(N + 1, 0);
std::vector<int> sorted;

for (int i = 0; i < M; i++) {
int a, b;
std::cin >> a >> b;
graph[a].push_back(b);
indegree[b]++;
}

std::queue<int> q;
for (int i = 1; i < N + 1; i++) {
if (indegree[i] == 0) q.push(i);
}

while (!q.empty()) {
int temp = q.front();
sorted.push_back(temp);
q.pop();
for (int i = 0; i < graph[temp].size(); i++) {
indegree[graph[temp][i]]--;
if (indegree[graph[temp][i]] == 0) {
q.push(graph[temp][i]);
}
}
Comment on lines +29 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ΄λ ‡κ²Œ 2차원 λ°°μ—΄μ²˜λŸΌ []κ°€ 많이 λΆ™λŠ” 경우, λœ»μ„ νŒŒμ•…ν•˜κΈ° μ–΄λ €μšΈ 수 μžˆμŠ΅λ‹ˆλ‹€. μ΄λ•Œ

for(auto next_node : graph[temp]) {
	indegree[next_node]--;
	if(indegree[next_node] == 0) {
		q.push(next_node);
	}
}

처럼 μ“°λ©΄ 가독성을 높여쀄 수 μžˆμ–΄μš”! temp도 nodeλ‚˜ cur_node 처럼 μ˜λ―ΈμžˆλŠ” 이름을 써주면 더 μ’‹κ² μ£ ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ΄ν„°λ ˆμ΄ν„°...μ˜€λ‚˜ 이름이

맨날 μ“°λŠ” μ›μ‹œμ μΈ CμŠ€νƒ€μΌ 말고 μƒˆλ‘œμš΄ C++ 적응은 μ–Έμ œλ‚˜ νž˜λ“  것 κ°™μŠ΅λ‹ˆλ‹€..ν•˜ν•˜

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

였~ μ΄λ ‡κ²Œ ν•˜λ©΄ 가독성이 ν™• λ‹¬λΌμ§€λ„€μš”!! κ΅Ώμž…λ‹ˆλ‹Ή

}

for (int i = 0; i < sorted.size(); i++) {
std::cout << sorted[i] << " ";
}
return 0;
}