Task: Implement can_achieve_any_configuration with File I/O
You must write a single cohesive solution that combines the original algorithmic task with a required file-based input/output workflow.
Algorithmic requirement (unchanged):
Implement the function can_achieve_any_configuration(n, edges) which determines whether any configuration of real numbers written on the edges of a tree can be achieved through a finite number of operations.
Return "YES" if all nodes have degree different from 2, otherwise return "NO".
Specifically:
If any node in the tree has degree exactly 2, return "NO".
If all nodes have degrees other than 2, return "YES".
File I/O requirement (NEW, combined with the algorithm):
The solution must be implemented in a single file: /app/solution.py.
The program should read input from a file and write output to a file, not rely on standard input/output for the final result.
Input format (in /app/input.txt):
Line 1: n (positive integer)
Lines 2 to n: each line contains two integers u v representing an edge of the tree (1-based node indices). There will be exactly n-1 edges.
Output format (written to /app/output.txt):
A single line containing either YES or NO, corresponding to the result of can_achieve_any_configuration(n, edges).
Implementation details to include in /app/solution.py:
Implement the function:
def can_achieve_any_configuration(n, edges):
# as described above
Provide a main routine that:
Reads the input from /app/input.txt
Parses n and the list of edges
Calls can_achieve_any_configuration(n, edges)
Writes the resulting string ("YES" or "NO") to /app/output.txt
Ensure the file path /app/solution.py is used for the implementation, and the program does not rely on stdout for the final answer.
Example (input/output behavior):
If input.txt contains:
3
1 2
1 3
4
1 2
2 3
2 4
Then input with multiple test cases is not required; follow the single-tree format. For the first tree, output.txt should contain YES; for the second tree, NO.
Note: The solution should be robust to the provided input format and assume valid trees (n nodes with exactly n-1 edges).