CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树。
析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1.
代码如下:
#include <bits/stdc++.h> using namespace std;
const int maxn =1000 + 5;
int p[maxn]; int Find(int x){ return x == p[x] ? x : p[x] = Find(p[x]); } int main(){
int n, m, x, y;
cin >> n >> m;
bool ok = true;
for(int i = 1; i <= n; ++i) p[i] = i;
for(int i = 0; i < m; ++i){
scanf("%d %d", &x, &y);
x = Find(x);
y = Find(y);
if(x == y) ok = false;
else p[y] = x;
} if(ok && m == n-1) puts("yes");
else puts("no");
return 0;
}
CodeForces 690C1 Brain Network (easy) (水题,判断树)的更多相关文章
- codeforces 690C1 C1. Brain Network (easy)(水题)
题目链接: C1. Brain Network (easy) time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- CodeForces 707A Brain's Photos (水题)
题意:给一张照片的像素,让你来确定是黑白的还是彩色的. 析:很简单么,如果有一种颜色不是黑白灰,那么就一定是彩色的. 代码如下: #pragma comment(linker, "/STAC ...
- Brain Network (easy)(并查集水题)
G - Brain Network (easy) Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- Brain Network (easy)
Brain Network (easy) One particularly well-known fact about zombies is that they move and think terr ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
- codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- CodeForces 589I Lottery (暴力,水题)
题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...
随机推荐
- DynamicConverter
folly/DynamicConverter.h When dynamic objects contain data of a known type, it is sometimes useful t ...
- oracle打补丁步骤简介
1.了解opatchopatch是用于维护"个别"补丁的,有人称其为interim path或是one-off patch该命令的存放位置在$ORACLE_HOME下的OPatch ...
- 利用Linux系统生成随机密码的9种方法
Linux操作系统的一大优点是对于同样一件事情,你可以使用高达数百种方法来实现它.例如,你可以通过数十种方法来生成随机密码.本文将介绍生成随机密码的十种方法. 1. 使用SHA算法来加密日期,并输出结 ...
- XML---Studying
XML 被设计用来传输和存储数据. HTML 被设计用来显示数据. 1.什么是 XML? XML 指可扩展标记语言(EXtensible Markup Language) XML 是一种标记语言,很类 ...
- Python 小知识点(10)--异常结构记录
try: print("try中") except KeyError as e: # 异常时,执行该块 print("异常中") else: # 主代码块(tr ...
- C#中的四舍五入有多坑
原文:C#中Math.Round()实现中国式四舍五入 C#中的Math.Round()并不是使用的"四舍五入"法.其实在VB.VBScript.C#.J#.T-SQL中Round ...
- bootstrap中的modal 模态弹出框不能放在 form_for里面,一弹出modal会自动submit掉form
bootstrap中的modal 模态弹出框不能放在 form_for里面,一弹出modal会自动submit掉form
- js中格式化时间
//时间格式化 Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, &quo ...
- pip / conda 导出和安装环境组件 requirements.txt
pip 批量导出包含环境中所有组件的requirements.txt文件 pip freeze > requirements.txt pip 批量安装requirements.txt文件中包含的 ...
- popup non topmost
public class PopupNonTopmost : Popup { public static DependencyProperty TopmostProperty = Window.Top ...