Codeforces Round #536 (Div. 2)--1106D - Lunar New Year and a Wander
https://codeforces.com/contest/1106/problem/D
题意:求出字典序最小的走法
解法:走到每个点,都选取与这个点连通的序号最小的点,并且这个序号最小的点没有被访问过。
#include<bits/stdc++.h>
using namespace std; int main(){
int n,m;
cin>>n>>m;
vector<vector<int> > g(n+);
for(int i=;i<m;i++){
int a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> visit(n+);
vector<int> path;
priority_queue<int,vector<int>,greater<int> > q;
q.push();
visit[]=;
while(!q.empty()){
int c=q.top();
q.pop();
path.push_back(c);
for(int j=;j<g[c].size();j++){
int d=g[c][j];
if(visit[d]!=){
q.push(d);
visit[d]=;
}
}
}
for(int i=;i<path.size();i++){
cout<<path[i]<<' ';
}
cout<<endl;
return ;
}
Codeforces Round #536 (Div. 2)--1106D - Lunar New Year and a Wander的更多相关文章
- Codeforces Round #536 (Div. 2) B. Lunar New Year and Food Ordering
#include <bits/stdc++.h> #define N 300010 #define PII pair<int, int> using namespace std ...
- Codeforces Round 536 (Div. 2) (E)
layout: post title: Codeforces Round 536 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces Round #536 (Div. 2) F 矩阵快速幂 + bsgs(新坑) + exgcd(新坑) + 欧拉降幂
https://codeforces.com/contest/1106/problem/F 题意 数列公式为\(f_i=(f^{b_1}_{i-1}*f^{b_2}_{i-2}*...*f^{b_k} ...
- Codeforces Round #536 (Div. 2) E dp + set
https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...
- Codeforces Round #536 (Div. 2)
前言 如您所见这又是一篇咕了的文章,直接咕了10天 好久没打CF了 所以还是个蓝名菜鸡 机房所有人都紫名及以上了,wtcl 这次前4题这么水虽然不知道为什么花了1h,结果不知道为什么搞到一半出锅了,后 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- github 添加wiki
亲们支持我的新博客哦==>地址(以后更新会尽量在新博客更新,欢迎大家访问加入我的后宫w) ) 平时都是写readMe和docs的,一直眼瞎没有注意到有wiki这个功能 随便找一个写了wiki的看 ...
- python3基础: 元组tuple、 列表list、 字典dict、集合set。 迭代器、生成器
一.元组: tuple Python 的元组与列表类似,不同之处在于元组的元素不能修改. 元组中的元素值是不允许删除的,但我们可以使用del语句来删除整个元组 tup2 = (111, 22, 33, ...
- poi横纵动态导入
dao层 <insert id ="saveInTarget" parameterType="java.util.List" > INSERT IN ...
- Oracle 事务和异常处理
Oracle 的异常和回滚 DECLARE dept_no ) :; BEGIN --开始事务 INSERT INTO dept VALUES (dept_no, '市场部', '北京'); --插入 ...
- 剑指offer例题——二进制中1的个数
题目:输入一个整数,输出该二进制表示中1的个数.其中负数用补码表示. 首先明确补码的定义: 原码 反码 补码 将最高位作为符号位(0表示正,1表示负), 其它数字位表达数值本身的绝对值的数字表示方式 ...
- maven pom.xml 项目报错
Failed to read artifact descriptor for org.springframework.boot:spring-boot-starter-web:jar:2.1.0.RE ...
- 使用 Composer 安装Laravel扩展包的几种方法
使用 Composer 安装Laravel扩展包的几种方法 以下的三种方法都是需要你在项目的根目录运行 第一种:composer install 如有 composer.lock 文件,直接安装,否则 ...
- 169. Majority Element (Array)
Given an array of size n, find the majority element. The majority element is the element that appear ...
- 算法练习LeetCode初级算法之数组
删除数组中的重复项 官方解答: 旋转数组 存在重复元素 只出现一次的数 官方解答: 同一个字符进行两次异或运算就会回到原来的值 两个数组的交集 II import java.util.Arr ...
- 100-days: eighteen
Title: Why India's election is among the world's most expensive election n.选举,当选,选举权 expensive adj.昂 ...