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!中可以组 ...
随机推荐
- 深入剖析JavaScript中的数据类型判断(typeof instanceof prototype.constructor)
关于JavaScript中的类型判断,我想大部分JavaScripter 都很清楚 typeof 和 instanceof,却很少有人知道 constructor,以及constructor与前面二 ...
- linux 必备 学习 资源 汇总 大全!
Linux https://www.linux.com/ https://youtu.be/CE4WeUNFX2g https://www.youtube.com/watch?v=JzsLkbwi1L ...
- vue 二级子路由跳转不了 bug
vue 二级子路由跳转不了 bug @click.prevent 阻止原生事件的冒泡 <li class="tools-hover-box-list-item" v-for= ...
- LeetCode 数组分割
LeetCode 数组分割 LeetCode 数组怎么分割可以得到左右最大值的差值的最大 https://www.nowcoder.com/study/live/489/1/1 左右最值最大差 htt ...
- 微软 AI 公开课
微软 AI 公开课 https://github.com/microsoft/ai-edu https://school.azure.cn/ https://docs.microsoft.com/le ...
- HTTP cache in depth
HTTP cache in depth HTTP 缓存 https://developers.google.com/web/fundamentals/performance/optimizing-co ...
- SDK & 埋点 & user behavior tracker
SDK & 埋点 & user behavior tracker 同一个 SDK ,根据不同的应用市场, 分别进行统计分析 ? https://www.umeng.com/ user ...
- 「NGK每日快讯」2021.2.3日NGK公链第92期官方快讯!
- 大数据开发-linux下常见问题详解
1.user ss is currently user by process 3234 问题原因:root --> ss --> root 栈递归一样 解决方式:exit 退出当前到ss再 ...
- DOM及相关操作
1.背景介绍 什么是DOM?简单地说,DOM是一套对文档的内容进行抽象和概念化的方法, 在现实世界里,人们对所谓的'世界对象模型'都不会陌生,例如,当用'汽车'.'房子'和'树'等名词来 ...