Codeforces Round #538 D. Lunar New Year and a Wander
题面:
题目描述:
题目分析:








1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <algorithm>
5 #include <vector>
6 #include <queue>
7 using namespace std;
8 const int maxn = 1e5+5;
9 int n, m;
10 vector<int> G[maxn]; //vector版邻接表
11 int vis[maxn]; //标记数组
12
13 struct cmp{ //比较函数,优先小的在队列前面
14 bool operator () (int a, int b){
15 return a > b;
16 }
17 };
18
19 void solve(){
20 priority_queue<int, vector<int>, cmp> q;
21 int u;
22 q.push(1);
23
24 while(!q.empty()){
25 u = q.top(); q.pop();
26
27 if(vis[u]) continue; //防止重复访问
28 vis[u] = 1; //标记
29
30 printf("%d ", u); //输出答案
31
32 for(int i = 0; i < G[u].size(); i++){
33 q.push(G[u][i]);
34 //把和u相连的点加入优先队列
35 }
36 }
37 }
38
39 int main(){
40 scanf("%d%d", &n, &m);
41
42 int u, v;
43 for(int i = 1; i <= m; i++){
44 scanf("%d%d", &u, &v);
45 G[u].push_back(v);
46 G[v].push_back(u);
47 }
48
49 solve();
50
51 return 0;
52 }
Codeforces Round #538 D. Lunar New Year and a Wander的更多相关文章
- Codeforces Round #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- Codeforces Round #538 (Div. 2) (CF1114)
Codeforces Round #538 (Div. 2) (CF1114) 今天昨天晚上的cf打的非常惨(仅代表淮中最低水平 先是一路缓慢地才A掉B,C,然后就开始杠D.于是写出了一个O( ...
- Codeforces Round #538 (Div. 2) C. Trailing Loves (or L'oeufs?) (分解质因数)
题目:http://codeforces.com/problemset/problem/1114/C 题意:给你n,m,让你求n!换算成m进制的末尾0的个数是多少(1<n<1e18 ...
- Codeforces Round #538 (Div. 2)
目录 Codeforces 1114 A.Got Any Grapes? B.Yet Another Array Partitioning Task C.Trailing Loves (or L'oe ...
- Codeforces Round #538 (Div. 2) F 欧拉函数 + 区间修改线段树
https://codeforces.com/contest/1114/problem/F 欧拉函数 + 区间更新线段树 题意 对一个序列(n<=4e5,a[i]<=300)两种操作: 1 ...
- Codeforces Round #538 (Div. 2) E 随机数生成
https://codeforces.com/contest/1114/problem/E 题意 交互题,需要去猜一个乱序的等差数列的首项和公差,你能问两种问题 1. 数列中有没有数比x大 2. 数列 ...
- Codeforces Round #538 (Div. 2) C 数论 + 求b进制后缀零
https://codeforces.com/contest/1114/problem/C 题意 给你一个数n(<=1e8),要你求出n!在b进制下的后缀零个数(b<=1e12) 题解 a ...
- Codeforces Round #538 (Div. 2) D. Flood Fill 【区间dp || LPS (最长回文序列)】
任意门:http://codeforces.com/contest/1114/problem/D D. Flood Fill time limit per test 2 seconds memory ...
- Codeforces Round #538 (Div. 2) CTrailing Loves (or L'oeufs?)
这题明白的意思就是求n!在b进制下的后缀零的个数. 即最大的n!%(b^k)==0的k的值.我们需要将如果要构成b这个数,肯定是由一个个质因子相乘得到的.我们只需要求出b的质因子,然后分析n!中可以组 ...
随机推荐
- 3.Work Queues
标题 : 3.Work Queues 目录 : RabbitMQ 序号 : 3 var channel1 = _connection.CreateModel(); channel1.BasicQos( ...
- C++ part5
为啥大三了课少了一点点,做作业的时间反而多了一大堆堆??? 关于protect 只能被本类或者子类的成员函数,或者友元函数访问. 友元函数: #include <iostream> #in ...
- 谈一谈phar 反序列化
前言 来自Secarma的安全研究员Sam Thomas发现了一种新的漏洞利用方式,可以在不使用php函数unserialize()的前提下,引起严重的php对象注入漏洞.这个新的攻击方式被他公开在了 ...
- TypeScript Generics All In one
TypeScript Generics All In one TypeScript 泛型 代码逻辑复用 扩展性 设计模式 方法覆写, 直接覆盖 方法重载,参数个数或参数类型不同 test " ...
- SEO & JSON-LD & structured-data
SEO & JSON-LD & structured-data script type="application/ld+json" script type=&quo ...
- Flutter CodePen challenges
Flutter CodePen challenges 挑战赛 https://mp.weixin.qq.com/s/qIYokWN9SVgr-F7YxbJuOQ CodePen Flutter 编辑器 ...
- HTML Custom Elements (v1)
HTML Custom Elements (v1) https://developers.google.com/web/fundamentals/web-components/customelemen ...
- image to cur (cursor icons)
image to cur (cursor icons) mouse-cursor-pointer https://onlineconvertfree.com/convert-format/jpg-to ...
- animejs 动画库
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Flutter 获取本地图片并剪切
安装依赖 dependencies: ... image_picker: image_cropper android\app\src\main\AndroidManifest.xml 将UCropAc ...