编程介的小学生 2019-08-25 22:10 采纳率: 20.5%
浏览 74

Play with Sequence的求解,用C语言

Problem Description
  ivankevin loves sequences.
  A sequence of n elements is called a SWITCH SEQUENCE iff:
  Each element is a 2-switch, where a 2-switch is the replacement of a pair of edges xy & zw in a simple graph by the edges yz and wx, given that yz and wx did not appear in the graph originally.
  Now give two simple graphs G and H with same vertex set V, ivankevin wants to know whether there is a switch sequence transforms G into H.

Input
  There are multiple test cases.
  Each case contains 1 + 2n lines. The positive integer n(0<n<101) is given in the first line. The next 2n lines are the matrix which describe the two graphs G and H. The j elements in the i rows is either 0 or 1. If the node i and the node j has a edge in the graph. The elements will be 1. Otherwise is 0. It’s guaranteed that the matrix is symmetry and the i elements in the i row is always 0. See sample input for more details.

Output
  For each case, first output an integer L in a line, which should represent the length of the switch sequence you found.
  If no switch sequence can transform G into H, then you should print L as -1 and no more lines. Otherwise output L lines follow. Each of the L lines should contains four distinct integers x, y, z and w, indicating a 2-switch on G, as described.       
  For some reason, if L is equal to or larger than 1000000, ivankevin would think the switch sequence you found is so ugly that it is ungelieveble and unacceptable. Otherwise, if L < 1000000 and the sequence finally transform G into H, he will accept your answer.

Sample Input
4
0 1 0 0
1 0 0 0
0 0 0 1
0 0 1 0
0 0 1 0
0 0 0 1
1 0 0 0
0 1 0 0
4
0 1 0 0
1 0 0 0
0 0 0 1
0 0 1 0
0 1 1 0
1 0 0 0
1 0 0 0
0 0 0 0

Sample Output
1
0 1 3 2
-1

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何修改pca中的feature函数
    • ¥20 java-OJ-健康体检
    • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
    • ¥15 使用phpstudy在云服务器上搭建个人网站
    • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
    • ¥15 vue3+express部署到nginx
    • ¥20 搭建pt1000三线制高精度测温电路
    • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
    • ¥15 画两个图 python或R
    • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法