▎🧩 D. Add on a Tree (Simplified)
You are given a tree (a connected graph with no cycles) of n nodes. Each edge in the tree initially has a value of 0.
You can perform the following operation:
> Choose any two leaf nodes (nodes connected to only one other node), and a real number x.
> Then, add
🔁 You can repeat this operation as many times as you want, with different pairs of leaves and values.
---
▎❓ Question
Is it possible to reach any possible configuration of real numbers on the edges using a finite number of such operations?
Print:
• YES — if it’s always possible for this tree
• NO — if there exists any configuration that you cannot reach
---
▎📥 Input
• First line:
• Next
It is guaranteed that the graph is a tree.
---
▎📤 Output
• Print YES or NO
---
▎📌 Examples
Input
Output
You are given a tree (a connected graph with no cycles) of n nodes. Each edge in the tree initially has a value of 0.
You can perform the following operation:
> Choose any two leaf nodes (nodes connected to only one other node), and a real number x.
> Then, add
x to all edges on the simple path between these two leaf nodes.🔁 You can repeat this operation as many times as you want, with different pairs of leaves and values.
---
▎❓ Question
Is it possible to reach any possible configuration of real numbers on the edges using a finite number of such operations?
Print:
• YES — if it’s always possible for this tree
• NO — if there exists any configuration that you cannot reach
---
▎📥 Input
• First line:
n — number of nodes (2 ≤ n ≤ 10⁵)• Next
n-1 lines: two integers u and v, meaning an edge between node u and node vIt is guaranteed that the graph is a tree.
---
▎📤 Output
• Print YES or NO
---
▎📌 Examples
Input
2
1 2
Output
YES
Leetcode with dani
▎🧩 D. Add on a Tree (Simplified) You are given a tree (a connected graph with no cycles) of n nodes. Each edge in the tree initially has a value of 0. You can perform the following operation: > Choose any two leaf nodes (nodes connected to only one other…
Answer :
def main():
def iinp(): return (int(input()))
def linp(): return (list(map(int, input().split())))
n = iinp()
arr = [0 for i in range(n+1)]
for i in range(n-1):
u,v = linp()
arr[u] += 1
arr[v] += 1
for i in arr:
if i ==2:
print("NO")
return
print("YES")
main()
E. Nauuo and Cards (Simplified Version)
Nauuo has 2n cards:
n real cards numbered from 1 to n
n empty cards, represented as 0
These cards are randomly shuffled and split into:
Nauuo’s hand → a list of n cards
The pile → another list of n cards, ordered top to bottom
✅ Operation
She can:
Choose any card from her hand, and
Play it — move it to the bottom of the pile,
Then draw the top card of the pile into her hand.
She wants the pile to end up as [1, 2, 3, ..., n] (from top to bottom) as fast as possible.
Nauuo has 2n cards:
n real cards numbered from 1 to n
n empty cards, represented as 0
These cards are randomly shuffled and split into:
Nauuo’s hand → a list of n cards
The pile → another list of n cards, ordered top to bottom
✅ Operation
She can:
Choose any card from her hand, and
Play it — move it to the bottom of the pile,
Then draw the top card of the pile into her hand.
She wants the pile to end up as [1, 2, 3, ..., n] (from top to bottom) as fast as possible.
Leetcode with dani
E. Nauuo and Cards (Simplified Version) Nauuo has 2n cards: n real cards numbered from 1 to n n empty cards, represented as 0 These cards are randomly shuffled and split into: Nauuo’s hand → a list of n cards The pile → another list of n cards, ordered…
def main():
n = int(input().strip())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pos = [0] * (n + 1)
for idx in range(n):
if b[idx]:
pos[b[idx]] = idx + 1
if pos[1] != 0:
i = 2
while i <= n and pos[i] == pos[1] + i - 1:
i += 1
if i - 1 >= 1 and pos[i - 1] == n:
j = i
while j <= n:
if pos[j] != 0 and pos[j] > j - i:
break
j += 1
else:
print(n - i + 1)
return
ans = 0
for card in range(1, n + 1):
if pos[card] != 0:
wait = pos[card] - card + 1
if wait > ans:
ans = wait
print(ans + n)
if __name__ == "__main__":
main()
Would you rather
Anonymous Poll
28%
Work with slow laptop and fast Internet
72%
Or slow Internet with fast laptop
🤯9
Some of you have been asking me for a structured DSA learning plan.
So I’m sharing the full A2SV year-long roadmap for learning Data Structures and Algorithms — the same one we follow as A2SV students.
If you want a curated collection of problems for each topic, just ask me and I’ll make and share one with you.
This roadmap is very comprehensive and teaches almost all key algorithms and patterns:
1. Python Basics, Conditionals, Loops Functions
2. How to Focus and Planning Time Management
3. DS Basics (Lists Tuples)
4. Best Coding Practices Code Review
5. DS Basics (Sets Dicts)
6. Built‑In Functions and Classes
7. 7 Steps of Highly Effective Problem Solving and Experience Sharing
8. Time Space Complexity
9. Arrays/Lists, Matrices
10. Sorting Part 1 (Bubble, Insertion, Counting, Selection)
11. Two Pointers
12. Sliding Window
13. Prefix Sum
14. Linked Lists I
15. Linked Lists II
16. Greedy
17. Stacks, Queues, Monotonicity
18. Recursion I
19. Tree I
20. Tree II
21. Recursion II
22. Binary Search
23. Sorting II – Part 1
24. Sorting II – Part 2
25. Graph
26. DFS
27. BFS
28. Topological Sort
29. Heap
30. Union Find
31. Bitwise
32. Numerics
33. Greedy II
34. Dynamic Programming I
35. Dynamic Programming II
36. Trie
37. Hashing
38. Strings
39. Shortest Path
40. Numerics II
41. Advanced String Algorithms
42. Segment Tree
So I’m sharing the full A2SV year-long roadmap for learning Data Structures and Algorithms — the same one we follow as A2SV students.
If you want a curated collection of problems for each topic, just ask me and I’ll make and share one with you.
This roadmap is very comprehensive and teaches almost all key algorithms and patterns:
1. Python Basics, Conditionals, Loops Functions
2. How to Focus and Planning Time Management
3. DS Basics (Lists Tuples)
4. Best Coding Practices Code Review
5. DS Basics (Sets Dicts)
6. Built‑In Functions and Classes
7. 7 Steps of Highly Effective Problem Solving and Experience Sharing
8. Time Space Complexity
9. Arrays/Lists, Matrices
10. Sorting Part 1 (Bubble, Insertion, Counting, Selection)
11. Two Pointers
12. Sliding Window
13. Prefix Sum
14. Linked Lists I
15. Linked Lists II
16. Greedy
17. Stacks, Queues, Monotonicity
18. Recursion I
19. Tree I
20. Tree II
21. Recursion II
22. Binary Search
23. Sorting II – Part 1
24. Sorting II – Part 2
25. Graph
26. DFS
27. BFS
28. Topological Sort
29. Heap
30. Union Find
31. Bitwise
32. Numerics
33. Greedy II
34. Dynamic Programming I
35. Dynamic Programming II
36. Trie
37. Hashing
38. Strings
39. Shortest Path
40. Numerics II
41. Advanced String Algorithms
42. Segment Tree
❤12
Forwarded from 「 Eyu core 」 (Eyu)
Six Uncomfortable Lessons We All Need to Learn
1 Your self-love must be stronger than your desire to be loved.
2 You are always responsible for your emotional reactions.
3 Don’t feed your problems with thought—starve them with action.
4 Your life will be defined by your ability to handle uncertainty.
5 If your goal is a healthier mind, start by removing the junk from your diet.
6 Your “best life” doesn’t seek validation—but insecurity will.
1 Your self-love must be stronger than your desire to be loved.
2 You are always responsible for your emotional reactions.
3 Don’t feed your problems with thought—starve them with action.
4 Your life will be defined by your ability to handle uncertainty.
5 If your goal is a healthier mind, start by removing the junk from your diet.
6 Your “best life” doesn’t seek validation—but insecurity will.
❤8
🔥 A2SV Prep + LeetCode Daily Practice Challange🔥
Hey everyone!
I’m starting a group for those who want to:
✅ Stay consistent by doing LeetCode daily
✅ Prepare for A2SV's next cohort (starting November)
✅ Build strong habits and problem-solving skills
✅ Support each other with discussion and motivation
🧠 In the group:
We’ll share daily questions from different DSA topics
You’ll pick at least one question to solve each day from the set
Questions will support both A2SV preparation and personal growth
You’re free to solve more if you want, but the goal is one a day minimum
Let’s grow together and stay accountable! 💪
Hey everyone!
I’m starting a group for those who want to:
✅ Stay consistent by doing LeetCode daily
✅ Prepare for A2SV's next cohort (starting November)
✅ Build strong habits and problem-solving skills
✅ Support each other with discussion and motivation
🧠 In the group:
We’ll share daily questions from different DSA topics
You’ll pick at least one question to solve each day from the set
Questions will support both A2SV preparation and personal growth
You’re free to solve more if you want, but the goal is one a day minimum
Let’s grow together and stay accountable! 💪
❤9⚡1
Are you interested in joining this LeetCode + A2SV prep group?
Anonymous Poll
77%
Yes, I’m in! Let’s go! 🚀
15%
I’m interested, but not sure if I can be active daily 🤔
8%
No, not now 🙅
⌨️ Would you rather:
Anonymous Poll
87%
Code with one hand because the other is injured
13%
Only code using voice dictation with constant mishearing?
👍5
Leetcode with dani
🔥 A2SV Prep + LeetCode Daily Practice Challange🔥 Hey everyone! I’m starting a group for those who want to: ✅ Stay consistent by doing LeetCode daily ✅ Prepare for A2SV's next cohort (starting November) ✅ Build strong habits and problem-solving skills ✅ Support…
Are you passionate about coding, collaboration, and community growth? Do you want of helping build a truly global hub where everyone—from beginners to seasoned pros—can learn, share, and level up together?
📩 DM me if you’re excited to make a real impact and help shape something BIG. Let’s build this LeetCoder family—together! 🚀
📩 DM me if you’re excited to make a real impact and help shape something BIG. Let’s build this LeetCoder family—together! 🚀
❤4
Leetcode with dani
Are you passionate about coding, collaboration, and community growth? Do you want of helping build a truly global hub where everyone—from beginners to seasoned pros—can learn, share, and level up together? 📩 DM me if you’re excited to make a real impact and…
@zprogramming_bot just say hi, i will respond ASAP
❤1
Leetcode with dani
🔥 A2SV Prep + LeetCode Daily Practice Challange🔥 Hey everyone! I’m starting a group for those who want to: ✅ Stay consistent by doing LeetCode daily ✅ Prepare for A2SV's next cohort (starting November) ✅ Build strong habits and problem-solving skills ✅ Support…
join this group guys https://news.1rj.ru/str/competitveprogrammingleague to join the comminity
❤5