-
Notifications
You must be signed in to change notification settings - Fork 2
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
44-tgyuuAn #159
44-tgyuuAn #159
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.
λ¬ΈλΉλ pr μ΄νμ λ°λ‘ νΈλΌμ΄ λ¬Έμ λ₯Ό νμ΄λ³΄μ
¨κ΅°μ μ€νλ ₯ γ·γ·!!
νΈλΌμ΄ 곡λΆνλ€κ° λμ
λ리λΆν° λ€μ 보λλΌ λ¦¬λ·°κ° μ¬λ λ¦μ΄μ‘μ΅λλ€ ... π
μ λ λ€μμ£Ό~λ€λ€μμ£Ό DP 곡λΆκ° λλλ©΄ νΈλΌμ΄ λ¬Έμ νμ΄λ³Όλ €κ³ λ¬Έμ λ μ°Ύμλ¨μ΄λ€ γ γ γ
μ΄λ²μ£Όλ λ¬Έμ νΈλλΌ κ³ μνμ ¨μ΄λ€-! πͺ
|
||
def input(): return sys.stdin.readline() | ||
|
||
class 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.
νμ΄μ¬μμμ class... κ±°μ μκ³ μ§λλ€μ
λ€μ class κ°λ
μ°Ύμ보면μ 볡μ΅νκ³ κ°λλ€ π₯π₯
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λ₯Ό μ§ννλλ°
- μ΄ λ μ¬μ μμΌλ‘ λΆλͺ¨ λ Έλλ₯Ό νμνλ©΄μ
- μΆλ ₯ν λ¬Έμμ΄μ κΉμ΄μ λ°λΌμ μ μ νκ² λ§λ€μ΄ λ°λ‘ 리μ€νΈμ μΆκ°νλ€μ
- μ΅μ’ μ μΌλ‘ μμ±λ 리μ€νΈλ₯Ό μΆλ ₯
μ¬μ μμΌλ‘ λνλ΄μΌ ν¨μ λ¬Έμ μμ μꡬν΄μ
μ²μμ λ무 볡μ‘νκ² μκ°νλλ° λ§μ νλ©΄μ 보λ 그리 κΉλ€λ‘μ§ μμκ³
μκ°λ³΄λ€ λ¨μνκ² νμ΄λ³Ό μ μμμ΅λλ€.
N = int(input())
tree = {}
for _ in range(N):
lst = input().split()
if lst[1] not in tree:
tree.setdefault(lst[1], {})
node = tree[lst[1]]
for i in range(2, len(lst)):
if lst[i] not in node:
node.setdefault(lst[i], {})
node = node[lst[i]]
result = []
def dfs(node, depth):
for char in sorted(node.keys()):
depths = '--' * depth
result.append(depths + char)
dfs(node[char], depth + 1)
for start in sorted(tree.keys()):
result.append(start)
dfs(tree[start], 1)
for v in result:
print(v)
#include <iostream>
#include <map>
using namespace std;
struct Tree {
struct Node {
map<string, Node *> children;
Node *getOrCreate(string &name) {
if (children.contains(name)) return children[name];
return children[name] = new Node();
}
};
void print(Node *cur, int depth = 0) {
for (auto [k, v]: cur->children) {
for (int i = 0; i < depth; i++) {
cout << "--";
}
cout << k << '\n';
print(v, depth + 1);
}
}
Node *root = new Node;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
Tree *tree = new Tree();
while (N--) {
int K;
cin >> K;
Tree::Node *cur = tree->root;
while (K--) {
string t;
cin >> t;
cur = cur->getOrCreate(t);
}
}
tree->print(tree->root);
return 0;
} νΈλΌμ΄ PR λ³΄κ³ λ°λ‘ νμ΄λ³΄λ λ₯λ ₯μγ·γ·γ·γ· |
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.
λ‘μ§μ΄ μ μ κ±°μ κ°μμ λ릴 λ§μμ΄ μλ€μ.
κ΅Ώμ λλ€.
π λ¬Έμ λ§ν¬
κ°λ―Έκ΅΄
βοΈ μμλ μκ°
30λΆ
κ·Έλ₯ solved.ac 6λν¬μμ μ무거λ 골λλλ°,
λ¬ΈλΉλμ΄ μ΅κ·Όμ νμλ νΈλΌμ΄κ° λ°λ‘ λ μ¬λμ.
νΈλΌμ΄κ·Έλ¦Όμ μκ³ μμμ§λ§ λ§μ ꡬνν΄λ³΄λ €λ μκ°λλ‘ λμ§ μμμ νΈλΌμ΄ μλ£κ΅¬μ‘° λ νΌλ°μ€λ₯Ό λ³΄κ³ λ§λ€μμ.
μμ§ μκ°λλ‘ μ λμ§ μμλ€. λ λ§μ μ°μ΅μ΄ νμν λ―.
β¨ μλ μ½λ
κ·Έλ¦Όμ λμμλ κ·Έλλ‘ νΈλΌμ΄ μλ£κ΅¬μ‘°λ₯Ό λ§λ€λ©΄ λλ λ¬Έμ μ΄λ€.
νΈλΌμ΄ μλ£κ΅¬μ‘°λ₯Ό μλλ λͺ¨λ₯΄λλλ₯Ό νκ°λ¦ νλ λ¬Έμ μΈ κ² κ°λ€.
νΈλΌμ΄ μλ£κ΅¬μ‘°λ #155 (comment) μ μ¬λΌμ¨ λ¬ΈλΉλ PRμμ κΈ΄λ΅νκ² μκ°λμ΄μλλ°,
μ€μ λ‘ κ΅¬νν΄λ³΄λ©΄ λ λ€λ₯Έ λλμ΄λ€.
μ΄ λλ λ νΌλ°μ€λ₯Ό 보면 μ’λ€.
μλ£κ΅¬μ‘°λ₯Ό λ§λ€κ³ λ°μ΄ν°λ₯Ό λ€ μ½μ νλλΌλ©΄,
κ°μ₯ λ£¨νΈ λ ΈλλΆν° μ¬μ μμΌλ‘ μνμ μ§νν΄μ£Όλ©΄ λλ€.
μ΄ λΆλΆλ νΈλΌμ΄ μλ£κ΅¬μ‘°μ λν κ°λ μ΄ λ§μ΄ λΆμ‘±ν΄μ ꡬννλ λ° μκ°μ΄ μ’ κ±Έλ Έλ€.
μλ‘μ΄ μ νμ μ ν΄λ³΄λ μ¬λ°κΈ°λ νμ§λ§ μ‘°κΈ νλ€κΈ°λ νλ€.
체νν λ κΉμ§ νΈλΌμ΄ λ¬Έμ λ₯Ό μ’ νμ΄λ΄μΌκ² λ€.
μ΄λ²μλ λ νΌλ°μ€λ₯Ό λ³΄κ³ κ΅¬νμ νμ§λ§,
λ€μ λ²μλ λ νΌλ°μ€λ₯Ό λ³΄μ§ μκ³ μ€μ€λ‘ ꡬνν΄λ΄μΌκ² λ°.
π μλ‘κ² μκ²λ λ΄μ©