Minimum Distance in a Star Graph
来源:互联网 发布:淘宝质量问题怎么投诉 编辑:程序博客网 时间:2024/06/17 19:38
In this problem, we will define a graph called star graph, and the question is to find the minimum distance between two given nodes in the star graph.
Given an integer nnn, an n−dimensionaln-dimensionaln−dimensional star graph, also referred to as SnS_{n}Sn, is an undirected graph consisting of n!n!n! nodes (or vertices) and ((n−1) ∗ n!)/2((n-1)\ *\ n!)/2((n−1) ∗ n!)/2 edges. Each node is uniquely assigned a label x1 x2 ... xnx_{1}\ x_{2}\ ...\ x_{n}x1 x2 ... xn which is any permutation of the n digits 1,2,3,...,n{1, 2, 3, ..., n}1,2,3,...,n. For instance, an S4S_{4}S4 has the following 24 nodes 1234,1243,1324,1342,1423,1432,2134,2143,2314,2341,2413,2431,3124,3142,3214,3241,3412,3421,4123,4132,4213,4231,4312,4321{1234, 1243, 1324, 1342, 1423, 1432, 2134, 2143, 2314, 2341, 2413, 2431, 3124, 3142, 3214, 3241, 3412, 3421, 4123, 4132, 4213, 4231, 4312, 4321}1234,1243,1324,1342,1423,1432,2134,2143,2314,2341,2413,2431,3124,3142,3214,3241,3412,3421,4123,4132,4213,4231,4312,4321. For each node with label x1 x2x3 x4 ... xnx_{1}\ x_{2} x_{3}\ x_{4}\ ...\ x_{n}x1 x2x3 x4 ... xn, it has n−1n-1n−1 edges connecting to nodes x2 x1 x3 x4 ... xnx_{2}\ x_{1}\ x_{3}\ x_{4}\ ...\ x_{n}x2 x1 x3 x4 ... xn,x3 x2 x1 x4 ... xnx_{3}\ x_{2}\ x_{1}\ x_{4}\ ...\ x_{n}x3 x2 x1 x4 ... xn,x4 x2 x3 x1 ... xnx_{4}\ x_{2}\ x_{3}\ x_{1}\ ...\ x_{n}x4 x2 x3 x1 ... xn, ..., and xn x2 x3 x4 ... x1x_{n}\ x_{2}\ x_{3}\ x_{4}\ ...\ x_{1}xn x2 x3 x4 ... x1. That is, the n−1n-1n−1 adjacent nodes are obtained by swapping the first symbol and the d−thd-thd−th symbol of x1 x2 x3 x4 ... xnx_{1}\ x_{2}\ x_{3}\ x_{4}\ ...\ x_{n}x1 x2 x3 x4 ... xn, for d=2,...,nd = 2, ..., nd=2,...,n. For instance, in S4S_{4}S4, node 123412341234 has 333 edges connecting to nodes 213421342134,321432143214, and 423142314231. The following figure shows how S4S_{4}S4 looks (note that the symbols aaa,bbb,ccc, and ddd are not nodes; we only use them to show the connectivity between nodes; this is for the clarity of the figure).
In this problem, you are given the following inputs:
- nnn: the dimension of the star graph. We assume that nnn ranges from 444 to 999.
- Two nodes x1x_{1}x1x2x_{2}x2x3x_{3}x3 ... xnx_{n}xn and y1y_{1}y1y2y_{2}y2y3 ... yny_{3}\ ...\ y_{n}y3 ... yn in SnS_{n}Sn.
You have to calculate the distance between these two nodes (which is an integer).
Input Format
nnn (dimension of the star graph)
A list of 555 pairs of nodes.
Output Format
A list of 555 values, each representing the distance of a pair of nodes.
样例输入
41234 42311234 31242341 13243214 42133214 2143
样例输出
12213
待解决
- Minimum Distance in a Star Graph
- ???Minimum Distance in a Star Graph
- Minimum Distance in a Star Graph(南宁网络赛)
- 计蒜客 Minimum Distance in a Star Graph 思维水题
- 2017 ACM-ICPC南宁网络赛: J. Minimum Distance in a Star Graph(BFS)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Minimum Distance in a Star Graph
- 2017 icpc 南宁赛区 J. Minimum Distance in a Star Graph(bfs)
- 计蒜客 Minimum Distance in a Star Graph 2017icpc南宁赛区 字符串bfs
- 2017南宁网络赛J.Minimum Distance in a Star Graph(bfs求最短路)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛- J. Minimum Distance in a Star Graph
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 J. Minimum Distance in a Star Graph
- Minimum Distance in a Star Graph BFS/康托展开 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛(J.Minimum Distance in a Star Graph)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 J Minimum Distance in a Star Graph 广度优先搜索
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 J.Minimum Distance in a Star Graph
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 J. Minimum Distance in a Star Graph(bfs+状态保存)
- Connectivity in a directed graph
- minimum value in a tree
- Spring Cloud 微服务实战——第1章 基础知识
- LAMP环境简单搭建
- 用HTML5实现手机摇一摇的功能并配上声音
- 交互式网页应用的网页开发技术Ajax简单介绍
- C++函数
- Minimum Distance in a Star Graph
- hrbust 软件与微电子学院 ACM 2017 级新人热身程序竞赛
- Maven POM中的各种scope的行为总结
- 为ListCtrl列表控件设置颜色
- java 行为型模式 观察者模式
- NYOJ-45-一笔画问题(搜索+欧拉定理)
- 我想学学
- 第四周周末总结
- Frequent Subsets Problem