【CS Round #43 D】Bad Triplet
【链接】点击打开链接
【题意】
【题解】
任取其3个出度a,b,c如果a和b有边相连,则输出x,a,b->一个长度为3的环如果a和c有边相连,则输出x,a,c如果b和c有边相连,则输出x,b,c上面三种情况都排除了,则直接输出a,b,c显然,它们互相之间的最短路都为2,因为上面的判断已经把最短路为1的情况排除掉了.
只有边数和点数相同的时候才是一个环.且环的大小为3的倍数才是一个合法的能够找到答案的环.
【错的次数】
【反思】
【代码】
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <cstdlib>
#include <cmath>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define ld long double
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rf(x) scnaf("%lf",&x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
#define sz(x) ((int) x.size())
#define ld long double typedef pair<int, int> pii;
typedef pair<LL, LL> pll; //mt19937 myrand(time(0));
//int get_rand(int n){return myrand()%n + 1;}
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e5; int n, m;
vector <int> g[N + 10];
map <int, bool> have[N + 10];
vector <int> v;
bool flag[N + 10]; void dfs(int x) {
if (flag[x]) return;
v.pb(x);
flag[x] = true;
int len = sz(g[x]);
rep1(i, 0, len - 1) {
int y = g[x][i];
dfs(y);
}
} int main() {
//Open();
//Close();
ri(n), ri(m);
rep1(i, 1, m) {
int x, y;
ri(x), ri(y);
g[x].pb(y), g[y].pb(x);
have[x][y] = true,have[y][x] = true;
}
rep1(i, 1, n)
if (sz(g[i])>=3){
int x = g[i][0], y = g[i][1], z = g[i][2];
if (have[x][y])
return printf("%d %d %d\n", i, x, y),0;
if (have[x][z])
return printf("%d %d %d\n", i, x, z), 0;
if (have[y][z])
return printf("%d %d %d\n", i, y, z), 0;
return printf("%d %d %d\n", x, y, z), 0;
}
if (n % 3 == 0 && n == m) {
dfs(1);
printf("%d %d %d\n", v[0], v[n / 3], v[n / 3 + n / 3]);
}
else puts("-1");
return 0;
}
【CS Round #43 D】Bad Triplet的更多相关文章
- 【CS Round #43 E】Coprime Pairs
[链接]点击打开链接 [题意] 让你选择n个数字,组成一个数组,使得这n个数字中恰好有k对,它们是互质的. [题解] 我们可以先找出前n个质数,那么接下来的问题就转化为,凑出rest = n*(n-1 ...
- 【CS Round #43 C】Rectangle Partition
[链接]点击打开链接 [题意] 有一辆火车,它的长度为L,然后假设这辆车现在随机可能地出现在0..D之间,然后假设它已经耗光了油. 问你它需要走的期望距离是多少. 这里要走的距离指的是车里最近的加油站 ...
- 【CS Round #43 B】Rectangle Partition
[链接]https://csacademy.com/contest/round-43/task/rectangle-partition/ [题意] 水题 [题解] 横着过去,把相邻的边的宽记录下来. ...
- 【CS Round #43 A】Expected Dice
[链接]https://csacademy.com/contest/round-43/task/expected-dice/ [题意] 大水题 [题解] 把36种可能的结果都存下来. 然后把重复出现的 ...
- 【CS round 34】Minimize Max Diff
[题目链接]:https://csacademy.com/contest/round-34/task/minimize-max-diff/ [题意] 给你n个数字; 数组按顺序不下降; 让你删掉k个数 ...
- 【CS Round 34】Max Or Subarray
[题目链接]:https://csacademy.com/contest/round-34/summary/ [题意] 让你找一个最短的连续子串; 使得这个子串里面所有数字or起来最大; [题解] 对 ...
- 【CS Round #36 (Div. 2 only) A】Bicycle Rental
[题目链接]:https://csacademy.com/contest/round-36/task/bicycle-rental/ [题意] 让你从n辆车中选一辆车; 每一辆车有3个属性 1.到达车 ...
- 【CS Round #37 (Div. 2 only) D】Reconstruct Graph
[Link]:https://csacademy.com/contest/round-37/task/reconstruct-graph/statement/ [Description] 给你一张图; ...
- 【CS Round #37 (Div. 2 only) B】Group Split
[Link]:https://csacademy.com/contest/round-37/task/group-split/ [Description] 让你把一个数分成两个数a.b的和; (a,b ...
随机推荐
- Ubuntu系统下的多路径软件 DM Multipath 配置。
Ubuntu系统下的多路径软件是操作系统自带的 DM Multipath工具.------------------------------------------------------------- ...
- tar---打包,解压缩linux的文件和目录
tar命令可以为linux的文件和目录创建档案.利用tar,可以为某一特定文件创建档案(备份文件),也可以在档案中改变文件,或者向档案中加入新的文件.tar最初被用来在磁带上创建档案,现在,用户可以在 ...
- docker on spark
从docker 仓库 pull 镜像 docker pull sequenceiq/spark:1.4.0 构建 docker 镜像 docker build –rm -t sequenceiq/sp ...
- 云计算时代告别phpMyAdmin
云计算时代告别phpMyAdmin phpMyAdmin是一款很经典的MySQL数据库管理工具,在云计算快速发展的今天,phpMyAdmin交互老旧.已经不能适应时代步伐.因此有很多人開始选择一些更高 ...
- 71.用express框架,出现 express.Router is not a function
Express版本太久
- 懒加载js实现和优化
1.懒加载的作用和原理 在我们展示多图片的场景下,类似淘宝或者百度图片,由于图片的数目过多,全部从服务器请求会给用户糟糕的用户体验,为了提升用户体验,我们这里使用懒加载,随着下拉逐步加载. 每个图片的 ...
- mybatis在XML中大于号转义字符
mybatis在编写sql时不能在XML里直接使用‘<’ 或者是 ‘>’ 在这里需要使用转义字符替换 下面列举常用的xml转义对应: * < < ...
- BZOJ4712: 洪水(树链剖分维护Dp)
Description 小A走到一个山脚下,准备给自己造一个小屋.这时候,小A的朋友(op,又叫管理员)打开了创造模式,然后飞到 山顶放了格水.于是小A面前出现了一个瀑布.作为平民的小A只好老实巴交地 ...
- Ansible学习记录五:PlayBook学习
0.介绍 Playbooks 是 Ansible 管理配置.部署应用和编排的语言,可以使用 Playbooks 来描述你想在远程主机执行的策略或者执行的一组步骤过程等 类似于一组任务集,定义好像项目, ...
- Linux下关机命令的区别 (halt,poweroff,reboot,shutdown,init)
1.shutdown shutdown命令安全地将系统关机. 而在系统关机前使用shutdown命令﹐系统管理员会通知所有登录的用户系统将要关闭.并且login指令会被冻结﹐即新的用户不能再登录 ...