-
Notifications
You must be signed in to change notification settings - Fork 0
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
14-bomik0221 #57
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ¬Έμ νμ΄ κ³ μνμ ¨μ΅λλ€~~~ κ·Έλ¦Όλ λͺ λ£νκ³ μ΄ν΄νκΈ° μ¬μ΄ νμ΄μλ κ² κ°μμ.
μμμ λ ¬μ μ¬μ΄ν΄μ΄ μλ λ¨λ°©ν₯ κ·Έλν(Directed Acyclic Graph, DAG)μμ μΈ μ μλ μ λ ¬ λ°©λ²μΈλ°μ, λ¬Έμ λ₯Ό λ΄€μ λ DAGκ° κ·Έλ €μ§λκ°? μ μ λ ¬μ΄ νμνκ°?λ₯Ό λ°μ Έλ³΄λ©΄ μμμ λ ¬ λ¬Έμ μΈμ§ μλμ§ νμ ν μ μμ΅λλ€.
κ°μΈμ μΌλ‘ μ²μ ν΄λ³΄λ μ₯λ₯΄λ 3λ¬Έμ μ©μ νμ΄λ΄μΌ 체λλλ€κ³ μκ°νλλ°, κΎΈμ€ν νμ΄λ³΄λ©΄ κΈλ°© κ°μ΄ μ€μ€ κ±°μμ!
for (int i = 0; i < graph[temp].size(); i++) { | ||
indegree[graph[temp][i]]--; | ||
if (indegree[graph[temp][i]] == 0) { | ||
q.push(graph[temp][i]); | ||
} | ||
} |
There was a problem hiding this comment.
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 μ²λΌ μλ―Έμλ μ΄λ¦μ μ¨μ£Όλ©΄ λ μ’κ² μ£ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ΄ν°λ μ΄ν°...μλ μ΄λ¦μ΄
맨λ μ°λ μμμ μΈ Cμ€νμΌ λ§κ³ μλ‘μ΄ C++ μ μμ μΈμ λ νλ κ² κ°μ΅λλ€..νν
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ€~ μ΄λ κ² νλ©΄ κ°λ μ±μ΄ ν λ¬λΌμ§λ€μ!! κ΅Ώμ λλΉ
μμμ λ ¬μ DFSλ₯Ό ν΅ν΄μλ ꡬν κ°λ₯ν©λλ€. κ·Έλ¦¬κ³ μ΄ κ²½μ° μ½λκ° λ μ¬νν΄μ§λλ€. μ§μ μ°¨μλ₯Ό κΈ°λ‘ν νμκ° μκ³ , κΈ°λ³Έ DFS μ½λλ₯Ό μ΄μ§λ§ λ³κ²½ν΄μ£Όλ©΄ λκ±°λ μ. #include <iostream>
#include <vector>
using namespace std;
int N, M;
vector<vector<int>> AdjacencyList;
vector<int> OrderOfVisit;
void DFS(vector<bool>& Visited, int SrcNode)
{
Visited[SrcNode] = true;
for(const int& DstNode : AdjacencyList[SrcNode])
{
if(!Visited[DstNode])
{
DFS(Visited, DstNode);
}
}
OrderOfVisit.emplace_back(SrcNode);
}
void TopologySort()
{
vector<bool> Visited(N + 1, false);
for(int Node = 1; Node <= N; ++Node)
{
if(!Visited[Node])
{
DFS(Visited, Node);
}
}
}
int main()
{
cin >> N >> M;
AdjacencyList.assign(N + 1, {});
while(M--)
{
int A, B;
cin >> A >> B;
AdjacencyList[A].emplace_back(B);
}
TopologySort();
for(auto it = OrderOfVisit.rbegin(); it != OrderOfVisit.rend(); ++it)
{
cout << *it << " ";
}
return 0;
} DFS μμμ λ ¬ w. C++ μ΄ ν¬μ€ν μ μ€λͺ μ΄ μ λμ΄μμ΄μ κ°μ΄ 첨λΆν΄λ΄ λλ€. |
DFSλ₯Ό ν΅ν΄ μ§μΆ κ°μ μ΄ μλ λ ΈλλΆν° λ°°μ΄μ λ£λ μ리ꡰμ. DFSλ‘ λ°©λ¬Έν λ Έλμ λ€μ λ Έλκ° μλ€λ©΄ κ±°κΈ°λ‘ μ¬κ·μ μ κ·Όν ν λκΉμ. μ΄λ¬λ©΄ λ€μ§ν μμμ λ ¬ λ°°μ΄μ΄ ꡬν΄μ§ κ±°κ³ , λ€μ§μΌλ©΄ μμμ λ ¬μ΄ λκ² λ€μ(rbegin(), rend()). μ€λλ μ§μ μ»μ΄κ°λλ€~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μλ 보미λ κ°μκΈ° μ΄λ €μ΄ λ¬Έμ λ₯Ό λ±νκ³ λ€κ³ μ€μ §λ€μ..γ·γ· μλμ€λ½μ΅λλ€
κ·Όλ° μ§μ μ°¨μ..?κ° λ¬΄μ¨ λ§μΈμ§ μ΄ν΄λ₯Ό λͺ»νλ€μ π’
κ·Έλνμμ A -> B λ‘ μ΄μ΄μ Έμλ€κ³ νμ λ, Bλ λ€μ΄μ€λ κ°μ (A -> B)μ΄ 1κ° μλ€ ν΄μ μ§μ μ°¨μ = 1 μ΄λΌκ³ λ§ν©λλ€. |
λμ μ€λͺ κ°μ¬ν©λλ€~!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
15μ°¨μ λ¦¬λ·°λ§ νλ©΄ λλ μ€ μμμ΅λλΉ γ γ ...
보미λ μ κ° μλ μ¬μ΄μ μ€λ ₯ λ무 λ°μ νμ
¨λλ°μ... λλ¨ν΄μ€....
μ°μ μμκ° λΆλΆλͺ
ν κ²½μ°λΌκ³ λ§μν΄μ£Όμ
¨λλ° μ§μ
μ°¨μκ° κ°μ κ²½μ°λ₯Ό μ΄μΌκΈ°νλ κ±ΈκΉμ?
λ°μ .. νκ±ΈκΉμ? μΉμ°¬λ°μΌλ μ’μΌλ©΄μλ λ¨Έμ±νλ€μ κ°μ¬ν©λλ€π |
π λ¬Έμ λ§ν¬
2252λ²: μ€ μΈμ°κΈ°
μ ν : κ·Έλν μ΄λ‘ , μμ μ λ ¬
βοΈ μμλ μκ°
1μκ° 30λΆ
β¨ μλ μ½λ
λ¬Έμ μ΄ν΄
Nλͺ μ νμλ€μ ν€ μμλλ‘ μ€μ μΈμ°λ €κ³ νλ€. λ νμμ ν€λ₯Ό λΉκ΅νλ λ°©λ²μ μ¬μ©νκΈ°λ‘ νμλ€. μΌλΆ νμλ€μ ν€λ₯Ό λΉκ΅ν κ²°κ³Όκ° μ£Όμ΄μ‘μ λ, μ€μ μΈμ°λ νλ‘κ·Έλ¨μ μμ±νμμ€. μ΄ λ λ΅μ΄ μ¬λ¬ κ°μ§μΈ κ²½μ°μλ μ무거λ μΆλ ₯νλ€.
μμ μ λ ₯, μΆλ ₯
첫째 μ€μ N(1 β€ N β€ 32,000), M(1 β€ M β€ 100,000)μ΄ μ£Όμ΄μ§λ€. Mμ ν€λ₯Ό λΉκ΅ν νμμ΄λ€. λ€μ Mκ°μ μ€μλ ν€λ₯Ό λΉκ΅ν λ νμμ λ²νΈ A, Bκ° μ£Όμ΄μ§λ€. μ΄λ νμ Aκ° νμ Bμ μμ μμΌ νλ€λ μλ―Έμ΄λ€.
νμλ€μ λ²νΈλ 1λ²λΆν° Nλ²μ΄λ€.
μ¬κ³ κ³Όμ
μμ μ λ ¬ λ¬Έμ μΈ κ²μ μκ³ νμμ΅λλ€! νμ§λ§ μμ μ λ ¬ κ°λ μ λν μ΄ν΄κ° λΆμ‘±ν΄μ κ·Έλ°μ§ ꡬνμ μ€λ μκ°μ μΌμ΅λλ€.
λ€μκ³Ό κ°μ μμμμ, 1μ 3λ³΄λ€ μμ μμΌνκ³ , 2λ 3λ³΄λ€ μμ μμΌν©λλ€. μ°μ μμκ° λΆλΆλͺ ν κ²½μ°μλ μ΄λ»κ² μ€μ μΈμλ μ λ΅μΌλ‘ μΈμ ν΄ μ€λ€κ³ νλ,
1 β 2 β 3
νΉμ2 β 1 β 3
μ΄ λ΅μ΄ λ©λλ€.κ·Έλμ λ€μκ³Ό κ°μ λ°©λ²μΌλ‘ μ½λλ₯Ό ꡬννμ΅λλ€.
[κ·Έλν μ λ ₯ λ°λ λΆλΆ]
μ λ ₯μ
a b
ννλ‘ λ°λλ°, μ΄κ²μ 곧 aβb κ·Έλνλ₯Ό λ»νλ―λ‘ λ€μκ³Ό κ°μ΄ μ λ ₯μ λ°μμ΅λλ€. κ·Έλ¦¬κ³ aλ³΄λ€ bμ μ§μ μ°¨μκ° 1 μΆκ°λμ΄μΌ νλ―λ‘ μ λ ₯ λ°μλ λ°λ‘ bμλ μ§μ μ°¨μλ₯Ό μΆκ°ν΄ μ£Όμμ΅λλ€. κ·Έλ¬λ©΄ λ€μκ³Ό κ°μ κ·Έλνλ₯Ό μ»κ² λ©λλ€.[μμμ λ ¬ λΆλΆ]
λ€μ μ½λλλ‘ μ§ννλ©΄, μ§μ μ°¨μκ° 0μΈ 1κ³Ό 2λ₯Ό νμ λ£μ΅λλ€. κ·Έλ¦¬κ³ 1μ νμμ κΊΌλ΄μ μ λ°°μ΄μ λ£μ ν, 1 κ³Ό μ΄μ΄μ§ 3μ μ§μ μ°¨μλ₯Ό 1λ‘ λ³κ²½ν©λλ€. λ§μ½ 2κ° λ¨Όμ λ€μ΄κ°λ€λ©΄? μ΄ λ¬Έμ μμλ μ무 λ¬Έμ μμ΄ 2μ λν΄ λκ°μ κ³Όμ μ μνν΄μ£Όλ©΄ λ©λλ€. μ°μ μμκ° κ°μ κ²½μ°μλ μ΄λ€ λ΅μ΄ λμ€λ okμΈ κ½€λ κ΄λν λ¬Έμ ..!
κ·Έλ¦¬κ³ 2λ κΊΌλ΄μ μ λ°°μ΄μ λ£κ³ , 2μ μ΄μ΄μ§ 3μ μ§μ μ°¨μλ₯Ό 1 λ΄λ €μ€λλ€. κ·Έλ¬λ©΄ μ΄μ 3μ μ§μ μ°¨μλ 0μ΄ λλ―λ‘ νμ λ€μ΄μ€κ² λκ³ , 3λ νμμ λΉ μ Έλμ μ λ°°μ΄μ λ€μ΄κ°λ©΄ μ€ μκΈ°κ° μλ£λ©λλ€. κ·Έλ¬λ©΄ λ΅μ μΆλ ₯ν΄μ£Όλ©΄ μμ±!
[λ΅ μΆλ ₯]
λ΅ μΆλ ₯μ κ°λ¨νκ² μκΉ νμμ κΊΌλΈ μλ₯Ό μ μ₯ν λ°°μ΄μ μ λ ₯λ°μ μμλλ‘ μΆλ ₯ν΄μ£Όλ©΄ λ©λλ€!
π μλ‘κ² μκ²λ λ΄μ©
μ§λλ² λ―Όμ² λ PR λ³΄κ³ μμμ λ ¬μ΄ λμ§ κ°μ΄ μ μ‘νκΈΈλ κ° μ‘κ³ κ³΅λΆν΄ λ΄€λλ°, μμ μ΄λ ΅λ€μ... λκ° μ λ― λ§ λ― νλ©΄μ λ¨Έλ¦Ώμμ μ μ°©νμ§λ μμμ§λ§ νΈλ λ°μλ μ±κ³΅ν λλ? λΉλΆκ° μμ μ λ ¬κ³Ό κ·Έλνμ λν 곡λΆλ₯Ό ν΄λ΄μΌ ν κ² κ°λ€μ.γ γ