Connection Status:
Competition Arena > AutomorphicTree
TCO 2014 Semifinal 1 · 2014-03-26 · by rng_58 · Brute Force, Graph Theory, Math
Class Name: AutomorphicTree
Return Type: int[]
Method Name: construct
Arg Types: (long long)
Problem Statement

Problem Statement

Consider a tree with V vertices labeled 0 through V-1. A bijective function f from {0, ..., V-1} to {0, ..., V-1} is called an automorphism of this tree if for any u and v, vertices u and v are directly connected by an edge if and only if vertices f(u) and f(v) are directly connected by an edge. In other words, an automorphism is any permutation of vertex labels such that after the permutation the tree looks the same as in the beginning. (Note that there is always at least one automorphism: the identity function.)

Cat Snuke became age years old today. You want to give him a birthday present that has something to do with his age. As he likes trees, you decided to give him a tree with exactly age automorphisms. Due to your budget you can only buy him a tree that contains between 1 and 200 vertices, inclusive.

You are given the long age. Find a tree that matches the above requirements and return a int[] with its description in the format specified below. If there are many such trees, you may return any of them. If there are no such trees, return an empty int[] instead.

Given that you want to return a tree with V vertices, you should return a int[] X with exactly 2V-1 elements: the number of vertices, followed by the list of edges. More precisely: X[0] should be V. For each edge in your tree, there must be an i between 0 and V-2, inclusive, such that X[2*i+1] and X[2*i+2] are the endpoints of that edge. Note that V must be between 1 and 200, inclusive.

Constraints

  • age will be between 1 and 10^18, inclusive.
Examples
0)
1
Returns: {1 }

A tree with only one vertex.

1)
2
Returns: {8, 0, 1, 0, 2, 0, 3, 3, 4, 4, 5, 0, 6, 6, 7 }
2)
3
Returns: { }
3)
4
Returns: {11, 0, 1, 0, 2, 3, 4, 3, 5, 0, 3, 0, 6, 6, 7, 7, 8, 3, 9, 9, 10 }
4)
5
Returns: { }
7)
8
Returns: {6, 0, 1, 1, 2, 3, 4, 4, 5, 4, 1 }

The return value describes the following tree with 6 vertices: 0 3 | | | | 1------4 | | | | 2 5 We can easily verify that it has exactly 8 automorphisms.

Submissions are judged against all 132 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class AutomorphicTree with a public method vector<int> construct(long long age) · 132 test cases · 2 s / 256 MB per case

Submitting as anonymous