P1481
B3616
看到要计算最短时间就知道要排序
并查集模板
反并查集 如果是朋友,合并a和b。
如果是敌人,合并a+n和b,b+n和a(a的敌人是b,b的敌人是a)
代码
并查集,用map映射下,然后记得记录父亲
cpp#include <cstdio> #include <iostream> #include <map> using namespace std;
#include <cstdio> #include <iostream> #include <map> using namespace std;