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的更多相关文章

  1. 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 ...

  2. Codeforces Round 536 (Div. 2) (E)

    layout: post title: Codeforces Round 536 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  3. 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} ...

  4. Codeforces Round #536 (Div. 2) E dp + set

    https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...

  5. Codeforces Round #536 (Div. 2)

    前言 如您所见这又是一篇咕了的文章,直接咕了10天 好久没打CF了 所以还是个蓝名菜鸡 机房所有人都紫名及以上了,wtcl 这次前4题这么水虽然不知道为什么花了1h,结果不知道为什么搞到一半出锅了,后 ...

  6. 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 ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. 【亲测】在网页上查找接口,Network--XHR,出来的每个Name都是后台的一个接口

  2. liunx 部署 spring boot

    Xshell for Xmanager Enterprise 4 (Build 0232)Copyright (c) 2002-2014 NetSarang Computer, Inc. All ri ...

  3. Android 开发 框架系列 OkHttp使用详解

    简介 okhttp是一个第三方类库,用于android中请求网络.这是一个开源项目,是安卓端最火热的轻量级框架,由移动支付Square公司贡献(该公司还贡献了Picasso和LeakCanary) . ...

  4. py库: arrow (时间)

    arrow是个时间日期库,简洁易用.支持python3.6 https://arrow.readthedocs.io/en/latest/ arrow官网api https://github.com/ ...

  5. python3中一句话定义函数

    import math as marea=lambda r:r**2*m.pi #定义一个计算圆的面积的函数area(8) 显示结果 201.06192982974676

  6. web监控,if 语句

    对页面的测试  curl "] #if [`curl -I http://10.0.0.7 &>/dev/null|head -l|grep 200|wc -l` -eq 1] ...

  7. leetcode49

    public class Solution { public IList<IList<string>> GroupAnagrams(string[] strs) { var L ...

  8. vue 全局组件【原】

    1.目录 2.内容 -Loading.vue <template> <div class="loading"> loading... </div> ...

  9. docker mysql Exit 1

    用laradock启动mysql时,state总是 Exit 1 ,docker-compose build后也没有效果 这时应该在-/.laradock/data(.env的DATA_PATH_HO ...

  10. 【转】vMAN 和 PVID

    vMAN关的情况下,如果用户的包内带有VLAN TAG,则以用户的TAG为准,如果用户的包内不带VLAN TAG,就打上PVID:vMAN开的情况下,无论用户的包内是否带有VLAN TAG,都强制在外 ...