调用者保证相同的关系不重复输入
输入:
模块间关系,注意最后一行没有“,”结尾样例:
输入:
{0x00, 0x01},{0x04, false}
代码(没有优化,只实现功能)
#include
#include
#include
#include
我的一些测试用例:
// 有断点,无循环
{0x00, 0x01},
{0x02, 0x03},
{0x03, 0x04}
{0x00, false},
{0x01, false},
{0x02, false},
{0x03, false},
{0x04, false}
// 有断点、有循环
{0x00, 0x01},
{0x01, 0x03},
{0x02, 0x04},
{0x03, 0x00}
{0x00, true},
{0x01, true},
{0x02, false},
{0x03, true},
{0x04, false}
// 无断点、无循环
{0x00, 0x02},
{0x02, 0x03},
{0x03, 0x04}
{0x00, false},
{0x02, false},
{0x03, false},
{0x04, false}
// 有断点、两个循环
{0x01, 0x02},
{0x03, 0x01},
{0x02, 0x03},
{0x04, 0x09},
{0x07, 0x05},
{0x05, 0x06},
{0x06, 0x07}
{0x01, true},
{0x02, true},
{0x03, true},
{0x04, false},
{0x05, true},
{0x06, true},
{0x07, true},
{0x09, false}
// 两个循环、其中一个有个把
{0x01, 0x02},
{0x03, 0x01},
{0x02, 0x03},
{0x04, 0x05},
{0x07, 0x05},
{0x05, 0x06},
{0x06, 0x07}
{0x01, true},
{0x02, true},
{0x03, true},
{0x04, false},
{0x05, true},
{0x06, true},
{0x07, true}
// 有循环、节点后面有分叉
{0x05, 0x01},
{0x01, 0x02},
{0x02, 0x04},
{0x02, 0x03},
{0x03, 0x01}
{0x01, true},
{0x02, true},
{0x03, true},
{0x04, false},
{0x05, false}
// 无循环、节点后有分叉
{0x01, 0x02},
{0x02, 0x04},
{0x02, 0x03}
{0x01, false},
{0x02, false},
{0x03, false},
{0x04, false}
// 有循环、节点后有分叉
{0x01, 0x02},
{0x02, 0x04},
{0x04, 0x01},
{0x02, 0x03},
{0x03, 0x05}
{0x01, true},
{0x02, true},
{0x03, false},
{0x04, true},
{0x05, false}
// 几点后有分叉、无循环
{0x01, 0x03},
{0x02, 0x05},
{0x01, 0x06},
{0x02, 0x07}
{0x01, false},
{0x02, false},
{0x03, false},
{0x05, false},
{0x06, false},
{0x07, false}
// 有循环,节点后有很多分叉
{0x05, 0x01},
{0x01, 0x02},
{0x02, 0x03},
{0x03, 0x06},
{0x02, 0x04},
{0x04, 0x01},
{0x04, 0x07}
{0x01, true},
{0x02, true},
{0x03, false},
{0x04, true},
{0x05, false},
{0x06, false},
{0x07, false}
// 循环带个把
{0x05, 0x01},
{0x01, 0x02},
{0x02, 0x03},
{0x03, 0x01}
{0x01, true},
{0x02, true},
{0x03, true},
{0x05, false}
// 大循环包裹小循环
{0x01, 0x02},
{0x02, 0x03},
{0x03, 0x01},
{0x01, 0x04},
{0x04, 0x05},
{0x05, 0x01}
{0x01, true},
{0x02, true},
{0x03, true},
{0x04, true},
{0x05, true}
// 有循环、节点后有分叉
{0x01, 0x02},
{0x02, 0x03},
{0x02, 0x04},
{0x03, 0x01},
{0x05, 0x01}
{0x01, true},
{0x02, true},
{0x03, true},
{0x04, false},
{0x05, false}
// 交叉循环
{0x05, 0x01},
{0x01, 0x02},
{0x02, 0x03},
{0x03, 0x04},
{0x04, 0x01},
{0x03, 0x07},
{0x07, 0x06},
{0x06, 0x04}
{0x01, true},
{0x02, true},
{0x03, true},
{0x04, true},
{0x05, false},
{0x06, true},
{0x07, true}
// 交叉循环
{0x05, 0x01},
{0x01, 0x02},
{0x02, 0x03},
{0x03, 0x04},
{0x04, 0x01},
{0x07, 0x03},
{0x06, 0x07},
{0x04, 0x06}
{0x01, true},
{0x02, true},
{0x03, true},
{0x04, true},
{0x05, false},
{0x06, true},
{0x07, true}
// 两个循环相连
{0x05, 0x01},
{0x01, 0x02},
{0x02, 0x03},
{0x03, 0x04},
{0x04, 0x01},
{0x04, 0x06},
{0x06, 0x07},
{0x08, 0x06},
{0x07, 0x08}
{0x01, true},
{0x02, true},
{0x03, true},
{0x04, true},
{0x05, false},
{0x06, true},
{0x07, true},
{0x08, true}
// 两个无关的环,有把
{0x01, 0x02},
{0x02, 0x03},
{0x03, 0x02},
{0x03, 0x04},
{0x04, 0x02},
{0x07, 0x08},
{0x08, 0x09},
{0x07, 0x09},
{0x09, 0x07}
// 两个相连的环,有把
{0x01, 0x02},
{0x02, 0x03},
{0x03, 0x02},
{0x03, 0x04},
{0x04, 0x02},
{0x07, 0x08},
{0x08, 0x09},
{0x07, 0x09},
{0x09, 0x07},
{0x03, 0x07}
{0x01, false},
{0x02, true},
{0x03, true},
{0x04, true},
{0x07, true},
{0x08, true},
{0x09, true}