【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 ...
随机推荐
- javaScript 三目运算符初探
三目运算符 三目运算符,又称条件运算符,是计算机语言的重要组成部分.它是唯一有3个操作数的运算符,所以有时又称为三元运算符.一般来说,三目运算符的结合性是右结合的. 定义 对于条件表达式b ? x : ...
- rman 备份并异机恢复
1.RMAN 备份脚本 RUN { CONFIGURE RETENTION POLICY DAYS; CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CO ...
- Python基础班培训视频课程
课程目录:│ ├─第01天视频│ │ 01-课程介绍.avi│ │ 02-什么是操作系统.avi│ │ 03-生活中的操作系统.avi│ │ 04-操 ...
- Swift学习笔记(6)--字典
1.定义 //1.基本定义 [key 1: value 1, key 2: value 2, key 3: value 3] var dict = ["name":"Xi ...
- xwiki操作手册
Xwiki官网:http://www.xwikichina.com/xwiki/bin/view/Main/中文官网. 1 用户管理 1.1 添加新用户 用户管理需要管理员权限,管理员登陆后 ...
- P2186 小Z的栈函数
P2186 小Z的栈函数 题目描述 小Z最近发现了一个神奇的机器,这个机器的所有操作都是通过维护一个栈来完成的,它支持如下11个操作: NUM X:栈顶放入X. POP:抛弃栈顶元素. INV:将栈顶 ...
- php中array_merge函数
php中array_merge函数 一.array_merge简介 (PHP 4, PHP 5, PHP 7) array_merge — 合并一个或多个数组 说明¶ array array_merg ...
- 戏说Linux商用数据库
戏说Linux商用数据库 上一篇文章(http://chenguang.blog.51cto.com/350944/277533)我介绍了Linux下几款开源数据库Mysql,MaxDB.Postgr ...
- Codefroces Educational Round 27 845G Shortest Path Problem?
Shortest Path Problem? You are given an undirected graph with weighted edges. The length of some pat ...
- HDU 2017 Multi-University Training Contest - Team 4 1009 1011
Questionnaire Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)T ...