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!中可以组 ...
随机推荐
- kubernetes跑jenkins动态slave
使用jenkins动态slave的优势: 服务高可用,当 Jenkins Master 出现故障时,Kubernetes 会自动创建一个新的 Jenkins Master 容器,并且将 Volume ...
- 牛客多校第八场E Explorer(左开右闭线段树+可撤回并查集)题解
题意: 传送门 有\(n\)个点构成一个无向图,每条边有\(L_i,R_i\)表示这条边只能允许编号为\(L_i\dots R_i\)的人通过,现在问你最多有几个人能从\(1\)走到\(n\). 思路 ...
- MarkDown(文本编译器)
MarkDown(一种高效的文本编译器) 推荐使用Typora 点击此处下载 使用方法 1. 首先创建一个文本文件xxx.txt. 2. 然后修改文件后缀为xxx.md.(可以记做玛德...) 3. ...
- npm-run-all
npm-run-all npm scripts https://www.npmjs.com/package/npm-run-all A CLI tool to run multiple npm-scr ...
- js & void() & void(0)
js & void() & void(0) https://www.runoob.com/js/js-void.html void() <a href="javascr ...
- windows driver 简单的驱动和通信
sysmain.c #pragma once #pragma warning(disable: 4100) #include <ntifs.h> #include <ntddk.h& ...
- Dart 处理json,built_value库
原文链接 文档 import 'dart:convert'; main() async { // json 转化为 map String jsonStr = ''' [ {"name&quo ...
- SPC空投价值高达310万美金,生态建设者直呼真香!
市场上面有句名言:"人赚不到自己认知以外的财富",这在数字加密上也是共通的.早在本月12日,也就是前天,NGK官方发行的第N波利好---SPC侧链代币空投已经陆续发放了,NGK以及 ...
- CentOS7集群环境Elastic配置
CentOS7集群环境Elastic配置 (首先去官网下载elasticsearch的source code并解压到/usr/soft目录下) (以下默认root账户) 1.更改配置文件 文件路径:/ ...
- 正月十五吃汤圆CountDownLatch
CountDownLatch实际应用 今天是正月十五,给大家拜个晚年啦! 元宵节是中国传统节日,吃汤圆不能少啊,今天我们统计下"叫练"吃汤圆时间,并用代码模拟下叫练吃汤圆!其中用到 ...