We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Search
- Cut the Tree
- Discussions
Cut the Tree
Cut the Tree
Sort by
recency
|
168 Discussions
|
Please Login in order to post a comment
Solution in Python
!/bin/python3
simpelst one and solvable one i tried
import math import os import random import re import sys sys.setrecursionlimit(10**6)
def cutTheTree(data, edges): n = len(data) # adjacency (1-based nodes): convert to 0-based indices adj = [[] for _ in range(n)] for u, v in edges: u -= 1; v -= 1 adj[u].append(v) adj[v].append(u)
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')