链接:https://codeforces.com/contest/1169/problem/B

题意:

Toad Ivan has mm pairs of integers, each integer is between 11 and nn, inclusive. The pairs are (a1,b1),(a2,b2),…,(am,bm)(a1,b1),(a2,b2),…,(am,bm).

He asks you to check if there exist two integers xx and yy (1≤x<y≤n1≤x<y≤n) such that in each given pair at least one integer is equal to xx or yy.

思路:

单独考虑两个完全不相同的对,例如(1,2)-(3,4), 出现这种对时,x和y只能再这两对中取,所以,用vector记录率先出现的一个队,再找没有出现过的队,如果找不到也无所谓,说明一个队里的已经覆盖了全部。

再对这最多四个值进行枚举对,挨个查找。

不过别人思路好像跟我不大一样

代码:

#include <bits/stdc++.h>using namespace std;typedef long long LL;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
pair<int, int> node[MAXN];
int Dis[MAXN];
int n, m, k, t;
int p, q, u, v;
int x, y, z, w;bool Serch(int a, int b)
{for (int i = 1;i <= m;i++){if (node[i].first != a && node[i].first != b && node[i].second != a && node[i].second != b)return false;}return true;
}int main()
{cin >> n >> m;vector<int> ser;bool flag = true;for (int i = 1;i <= m;i++){cin >> node[i].first >> node[i].second;/*Dis[node[i].first]++;if ((Dis[node[i].first] == 1&& flag)){ser.push_back(node[i].first);if (ser.size() == 4)flag = false;}Dis[node[i].second]++;if ((Dis[node[i].second] == 1&& flag)){ser.push_back(node[i].second);if (ser.size() == 4)flag = false;}*/if (ser.size() < 4){bool f = true;for (int j = 0; j < ser.size(); j++)if (node[i].first == ser[j])f = false;for (int j = 0; j < ser.size(); j++)if (node[i].second == ser[j])f = false;if (f)ser.push_back(node[i].first), ser.push_back(node[i].second);}}flag = false;
//    cout << Serch(2, 4) << endl;
//    for (auto x:ser)
//        cout << x << ' ' ;
//    cout << endl;for (int i = 0;i < ser.size();i++)for (int j = i+1;j < ser.size();j++)if (Serch(ser[i], ser[j]))flag = true;if (flag)cout << "YES" << endl;elsecout << "NO" << endl;return 0;
}

  

转载于:https://www.cnblogs.com/YDDDD/p/10930203.html

Codeforces Round #562 (Div. 2) B. Pairs相关推荐

  1. Codeforces Round #562 (Div. 2) A.Circle Metro

    链接:https://codeforces.com/contest/1169/problem/A 题意: The circle line of the Roflanpolis subway has n ...

  2. Codeforces Round #592 (Div. 2) G. Running in Pairs 构造(水)

    传送门 文章目录 题意: 思路: 题意: 思路: 史上最水GGG题,没有之一. 考虑最小的情况如何构造,显然就是让a,ba,ba,b都1−n1-n1−n依次排列即可,这样的最小值为n∗(n+1)2\f ...

  3. Codeforces Round #729 (Div. 2)

    Codeforces Round #729 (Div. 2) 题号 题目 知识点 A Odd Set B Plus and Multiply C Strange Function D Priority ...

  4. Codeforces Round #703 (Div. 2)

    Codeforces Round #703 (Div. 2) 题号 题目 知识点 A Shifting Stacks 思维 B Eastern Exhibition 思维 C1 Guessing th ...

  5. Codeforces Round #597 (Div. 2) - BenFromHRBUST

    Codeforces Round #597 (Div. 2) -----比赛传送门----- A - Good ol' Numbers Coloring Problem Description Con ...

  6. Codeforces Round #797 (Div. 3)无F

    Codeforces Round #797 (Div. 3)无F 这打的也太屎了,白天把G补了才知道简单的很,但f还是没头绪呜呜呜 Problem - A - Codeforces Given the ...

  7. Codeforces Round #662 (Div. 2) B. Applejack and Storages

    Codeforces Round #662 (Div. 2) B. Applejack and Storages 题目链接 This year in Equestria was a year of p ...

  8. Codeforces Round #636 (Div. 3) D.Constant Palindrome Sum

    Codeforces Round #636 (Div. 3) D.Constant Palindrome Sum 题目链接 You are given an array a consisting of ...

  9. Codeforces Round #400 (Div. 1 + Div. 2, combined) 776E. The Holmes Children(待翻译)

    Codeforces Round #241 (Div. 2) 514C Watto and Mechanism ≤,≠,≥<> 时间限制:1S / 空间限制:256MB [在线测试提交传送 ...

最新文章

  1. WF4 Beta,RC版文章总结
  2. 你还在为 TCP 重传、滑动窗口、流量控制、拥塞控制发愁吗?看完图解就不愁了...
  3. hive mysql 远程_ubuntu中为hive配置远程MYSQL database
  4. nginx FastCGI错误Primary script unknown解决办法
  5. matlab模拟塞曼图谱,塞曼效应以及能级的计算
  6. OutOfMemoryError/OOM/内存溢出异常实例分析--堆内存溢出
  7. python基础---面向过程编程
  8. java 异常堆栈输出_打印Java异常堆栈信息
  9. kafka 丢弃数据_Kafka史上最详细原理总结下
  10. Nmap绕过防火墙脚本的使用
  11. (转) 淘淘商城系列——Redis的安装
  12. 最新.NET 5.0 C#6 MVC6 WCF5 NoSQL Azure开发120课视频
  13. 2021牛客寒假算法基础集训营4,签到题AGJ
  14. ES6、7学习笔记(尚硅谷)-5-箭头函数
  15. 5G 协议 标准 下载
  16. 【好书推荐】-你的灯亮着吗?
  17. php万能密码在线视频讲解,万能密码
  18. guge图标——ps
  19. 未转变者服务器载具名称,未转变者可以乘坐哪些车及载具参数介绍
  20. docker部署eureka时无法启动容器(问题解决)

热门文章

  1. 右键缺少open terminal选项的解决方法
  2. 《VMware Virtual SAN权威指南》一2.2 VSAN的要求
  3. H3C Boot升级 Serial模式
  4. puppet中master和agent之间实现通信
  5. pageEncoding和ContextType区别
  6. 字典 update()
  7. unix编程艺术的设计原则
  8. web开发流程 - 网上商城示例
  9. ubuntu+php+mysql+apache安装配置
  10. android ndk怎样加载o文件_JNI初探之NDK 开发环境配置