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!中可以组 ...
随机推荐
- 创建AVL树,插入,删除,输出Kth Min
https://github.com/TouwaErioH/subjects/tree/master/C%2B%2B/PA2 没有考虑重复键,可以在结构体内加一个int times. 没有考虑删除不存 ...
- 逆元 exgcd 费马小定理 中国剩余定理的理解和证明
一.除法取模逆元 如果我们要通过一个前面取过模的式子递推出其他要取模的式子,而递推式里又存在除法 那么一个很尴尬的事情出现了,假如a[i-1]=100%31=7 a[i]=(a[i-1]/2)%31 ...
- Python源码剖析——02虚拟机
<Python源码剖析>笔记 第七章:编译结果 1.大概过程 运行一个Python程序会经历以下几个步骤: 由解释器对源文件(.py)进行编译,得到字节码(.pyc文件) 然后由虚拟机按照 ...
- js map(Number) All In One
js map(Number) All In One map() 方法创建一个新数组,其结果是该数组中的每个元素是调用一次提供的函数后的返回值. let newArray = arr.map(callb ...
- React Portal All In One
React Portal All In One react multi root https://reactjs.org/docs/portals.html https://zh-hans.react ...
- Google Chrome All In One
Google Chrome All In One Chrome Experiments Chrome 测试版 Chrome 开发者版 Chrome Canary 版 chrome://welcome/ ...
- sketch 导出 svg
sketch 导出 svg refs xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
- nasm aat函数 x86
xxx.asm: %define p1 ebp+8 %define p2 ebp+12 %define p3 ebp+16 section .text global dllmain dllmain: ...
- flutter 长按图片保存到手机
main.dart import 'dart:io'; import 'package:flutter/material.dart'; import 'package:http/http.dart' ...
- 「NGK每日快讯」2021.1.21日NGK公链第79期官方快讯!