Permuting Edges: When node i → j, every edge {i, k} → {j, k}.
Input
One line with k space-separated integers: n₁ n₂ ... nₖ.
Meaning: n nodes partitioned into k contiguous groups:
Group 1: Nodes [1, 2, ..., n₁]
Group 2: Nodes [n₁+1, ..., n₁+n₂]
...
Group k: Nodes [n₁+...+nₖ₋₁+1, ..., n].
Output
For each group i (from 1 to k):
Define:
sum(i) = n₁ + n₂ + ... + nᵢ (set sum(0) = 0).
Group i contains nodes [Lᵢ, Rᵢ] where Lᵢ = sum(i-1) + 1, Rᵢ = sum(i).
If nᵢ > 1:
Output a line for the edge permutation induced by the full node cycle(Lᵢ, Lᵢ+1, ..., Rᵢ).
If nᵢ > 2:
Output an additional line for the edge permutation induced by the 2-cycle(Lᵢ, Lᵢ+1).
If nᵢ < 2: Skip group i.
Output Format Rules:
Each line is the full cycle notation of the edge permutation:
Cycles are disjoint and ordered by their smallest element (ascending).
Within a cycle: Start with smallest element, then s(a), s(s(a)), etc.
Fixed edges (1-cycles) omitted.
Key Clarification
Edge Representation in Output:
All edges in the output must be represented as positive integers corresponding to their lexicographic index (as defined above). The cycle notation for edge permutations must use these integer indices.
Allowed Languages
C++, Fortran, Python.
Assistant
Understanding the Problem
First, let's break down the problem into manageable parts:
Graph Structure: We have a complete graph with n nodes labeled from 1 to n. The edges are undirected and labeled lexicographically. For example, with n=3, the edges are:
{1,2} → 1
{1,3} → 2
{2,3} → 3
Node Groups: The nodes are partitioned into k contiguous groups based on the input n₁, n₂, ..., nₖ. For example, if input is 2 3, then:
Group 1: nodes 1, 2
Group 2: nodes 3, 4, 5
Permutations:
Full Node Cycle: For a group with nᵢ > 1, we consider the cycle (Lᵢ, Lᵢ+1, ..., Rᵢ) where Lᵢ and Rᵢ are the first and last nodes of the group.
2-Cycle: For a group with nᵢ > 2, we also consider the 2-cycle (Lᵢ, Lᵢ+1).
Edge Permutation: When we permute the nodes, the edges are permuted accordingly. For example, if we swap nodes 1 and 2:
Edge {1,2} (index 1) becomes {2,1} (same edge, so index 1 maps to 1).
Edge {1,3} (index 2) becomes {2,3} (index 3), so index 2 maps to 3.
Edge {2,3} (index 3) becomes {1,3} (index 2), so index 3 maps to 2.
Steps to Solve the Problem
Calculate Edge Indices: For any edge {i,j} with i < j, its index is (i-1)*n - i*(i+1)/2 + j.
Generate Node Permutations:
For the full cycle (Lᵢ, Lᵢ+1, ..., Rᵢ), the permutation maps Lᵢ → Lᵢ+1, Lᵢ+1 → Lᵢ+2, ..., Rᵢ → Lᵢ.
For the 2-cycle (Lᵢ, Lᵢ+1), the permutation swaps Lᵢ and Lᵢ+1.
Compute Edge Permutation:
For each edge , apply the node permutation to both and to get the new edge .
{a,b}
a
b
{a', b'}
Find the index of the new edge and map the original edge's index to this new index.
Cycle Notation:
Represent the edge permutation in cycle notation, omitting fixed points (1-cycles).
import sys
from collections import defaultdict
def edge_index(n, i, j):
if i > j:
i, j = j, i
return (i - 1) * n - i * (i + 1) // 2 + j
def compute_edge_permutation(n, node_perm):
edge_map = {}
total_edges = n * (n - 1) // 2
for a in range(1, n + 1):
for b in range(a + 1, n + 1):
original_index = edge_index(n, a, b)
new_a = node_perm[a - 1]
new_b = node_perm[b - 1]
if new_a > new_b:
new_a, new_b = new_b, new_a
new_index = edge_index(n, new_a, new_b)
if original_index != new_index:
edge_map[original_index] = new_index
return edge_map
def to_cycle_notation(edge_map):
visited = set()
cycles = []
for start in sorted(edge_map.keys()):
if start not in visited:
cycle = []
current = start
while current not in visited:
visited.add(current)
cycle.append(current)
current = edge_map.get(current, current)
if current == start:
break
if len(cycle) > 1:
cycles.append(tuple(cycle))
return cycles
def solve():
input_line = sys.stdin.readline().strip()
groups = list(map(int, input_line.split()))
n = sum(groups)
sum_prev = 0
for ni in groups:
if ni > 1:
L = sum_prev + 1
R = sum_prev + ni
# Full cycle (L, L+1, ..., R)
node_perm = list(range(1, n + 1))
for i in range(L, R):
node_perm[i - 1] = i + 1
node_perm[R - 1] = L
edge_map = compute_edge_permutation(n, node_perm)
cycles = to_cycle_notation(edge_map)
if cycles:
print(''.join(f"({','.join(map(str, cycle))})" for cycle in cycles))
if ni > 2:
# 2-cycle (L, L+1)
node_perm = list(range(1, n + 1))
node_perm[L - 1], node_perm[L] = node_perm[L], node_perm[L - 1]
edge_map = compute_edge_permutation(n, node_perm)
cycles = to_cycle_notation(edge_map)
if cycles:
print(''.join(f"({','.join(map(str, cycle))})" for cycle in cycles))
sum_prev += ni
if __name__ == '__main__':
solve()