题意:给定 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) (水题,判断树)的更多相关文章

  1. codeforces 690C1 C1. Brain Network (easy)(水题)

    题目链接: C1. Brain Network (easy) time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  2. CodeForces 707A Brain's Photos (水题)

    题意:给一张照片的像素,让你来确定是黑白的还是彩色的. 析:很简单么,如果有一种颜色不是黑白灰,那么就一定是彩色的. 代码如下: #pragma comment(linker, "/STAC ...

  3. Brain Network (easy)(并查集水题)

    G - Brain Network (easy) Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  4. Brain Network (easy)

    Brain Network (easy) One particularly well-known fact about zombies is that they move and think terr ...

  5. 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 ...

  6. codeforces 696A Lorenzo Von Matterhorn 水题

    这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...

  7. codeforces 577B B. Modulo Sum(水题)

    题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  9. CodeForces 589I Lottery (暴力,水题)

    题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...

随机推荐

  1. node的express中间件之static之ajax提交json

    static中间件可以使客户端直接访问网站中的所有静态文件. 利用这个功能可以直接把服务器上的静态页面直接读取出来返回到客户端. 从客户端点击一个按钮,向服务器端发送数据.并且插入到mysql数据库中 ...

  2. sqlldr并发

    sage: SQLLDR keyword=value [,keyword=value,...]   部分关键字:     userid -- ORACLE username/password    c ...

  3. 浅谈OPP

    了解Java或C#等面向对象编程语言的的程序员比较熟悉类和对象以及OOP. 一谈起OOP,就会想起教科书式的OOP概念:封装.继承.多态.粗浅的解释封装就是对数据进行隐藏:继承就是子类继承父类(cla ...

  4. nodeJS的了解

    JavaScript不仅仅只能运行在浏览器中.任何有JS运行环境(runtime)的地方就可以运行JavaScript. Node.js对Google V8进行了封装. 有了Node.js,JavaS ...

  5. canvas绘制圆弧

    canvas绘制圆弧 方法 anticlockwise为true表示逆时针,默认为顺时针 角度都传的是弧度(弧度 = (Math.PI/180)*角度) arc(x, y, radius, start ...

  6. 第二章:Android Studio概述(一)[学习Android Studio汉化教程]

     Android Studio是一个视窗化的开发环境.为了充分利用有限的屏幕空间,不让你束手束脚,Android Studio 在特定的时间仅仅显示一小部分可用窗口. 除了一些上下文敏感的窗口和上下文 ...

  7. leetcode495

    public class Solution { public int FindPoisonedDuration(int[] timeSeries, int duration) { ) { ; } ) ...

  8. java 控制台 输入字符串

    import java.util.Scanner; //导入输入类 public static void main(String[] args) {      //创建输入对象   Scanner s ...

  9. 页面生成柱状图 --- D3.js

    转载自:https://www.cnblogs.com/fastmover/p/7779660.html D3.js从入门到"放弃"指南 前言 近期略有点诸事不顺,趁略有闲余之时, ...

  10. angularjs 出现 “Possibly unhandled rejection: cancel ”错误

    Try adding this to your config. I had a similar is once and this workaround did the trick. app.confi ...