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!中可以组 ...
随机推荐
- KafkaConsumer 简析
使用方式 创建一个 KafkaConsumer 对象订阅主题并开始接收消息: Properties properties = new Properties(); properties.setPrope ...
- 一篇文章图文并茂地带你轻松学会 HTML5 storage
html5 storage api localStorage 和 sessionStorage 是 html5 新增的用来存储数据的对象,他们让我们可以以键值对的形式存储信息. 为什么要有 stora ...
- PAT l2-010 排座位 【并查集】
L2-010. 排座位 时间限制 150 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 布置宴席最微妙的事情,就是给前来参宴的各位宾客安排座位. ...
- codefroces 7C
C. Line time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Vue computed props pass params
Vue computed props pass params vue 计算属性传参数 // 计算 spreaderAlias spreaderAlias () { console.log('this. ...
- ES2021 & Pipeline operator (|>) / 管道运算符 |>
ES2021 & Pipeline operator (|>) / 管道运算符 |> demo "use strict"; /** * * @author xg ...
- web cache & web storage all in one
web cache & web storage all in one web cache in action web cache best practices web storage in a ...
- ES-Next & ECMAScript 2019
ES-Next & ECMAScript 2019 Data Types 8 种 js 基本数据类型 8 zhon The latest ECMAScript standard defines ...
- JavaScript高级-类的使用
1.面向过程与面向对象 1.1面向过程 面向过程就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现,使用的时候再一个一个的依次调用就可以了. 1.2面向对象 面向对象是把事务分解成为一个 ...
- Unity安卓apk打包过程
前言:对于Unity开发小白来说,Android打包无疑是个头痛的问题,所以我总结了 Unity安卓APK的打包过程 第一步:下载对应版本的Android Platform 第二步:安装JDK并配置J ...