首页 > 其他分享 >AtCoder Beginner Contest 168 D - .. (Double Dots)

AtCoder Beginner Contest 168 D - .. (Double Dots)

时间:2023-02-03 11:31:38浏览次数:61  
标签:Dots AtCoder Beginner int rep 房间 bfs ans tmp


AtCoder Beginner Contest 168 D - .. (Double Dots)_最短路径


AtCoder Beginner Contest 168 D - .. (Double Dots)_最短路径_02

题意:

AtCoder Beginner Contest 168 D - .. (Double Dots)_最短路径_03 个房间,在这些房间中两两连 AtCoder Beginner Contest 168 D - .. (Double Dots)_最短路径_04 次条边,问除了第一个房间,其他房间走到第一个房间的最短路径,输出这个房间所连的上一个房间,如果走不到,输出 AtCoder Beginner Contest 168 D - .. (Double Dots)_最短路径_05.
AtCoder Beginner Contest 168 D - .. (Double Dots)_最短路径_06

AC代码;

const int N = 1e6 + 50;
int n, m;
int u, v;
int ans[N];
vector<int> s[N];

void bfs()
{
queue<int> q;
q.push(1);
ans[1] = 1;
while (!q.empty())
{
int tmp = q.front();
q.pop();
for (auto w : s[tmp])
{
if (ans[w] == 0)
{
ans[w] = tmp;
q.push(w);
}
}
}
}

int main()
{
sdd(n, m);
rep(i, 1, m)
{
sdd(u, v);
s[u].pb(v);
s[v].pb(u);
}
bfs();
rep(i, 1, n)
{
if (ans[i] == 0)
{
puts("No");
return 0;
}
}
puts("Yes");
rep(i, 2, n)
pd(ans[i]);
return 0;
}


标签:Dots,AtCoder,Beginner,int,rep,房间,bfs,ans,tmp
From: https://blog.51cto.com/u_15952369/6035740

相关文章

  • [ABC266] AtCoder Beginner Contest 266
    比赛链接:Tasks-AtCoderBeginnerContest266先贴代码,题解有空再补。TasksTaskNameTimeLimitMemoryLimitAMiddleLetter2sec1024MBSubmit......
  • Atcoder ABC282F Union of Two Sets
    https://atcoder.jp/contests/abc282/tasks/abc282_fST表板子???这怎么出的?发现要每一个区间都能拆分成至多两个区间,那很明显就能联想到ST表的查询。大概算一下发现......
  • Atcoder ABC282E Choose Two and Eat One
    https://atcoder.jp/contests/abc282/tasks/abc282_e发现选出两个球去掉一个球其实很像一颗树去掉叶子节点,贡献即为叶子节点与父亲的边权。那这题就很明显了,预处理好每......
  • Atcoder ABC282H Min + Sum
    https://atcoder.jp/contests/abc282/tasks/abc282_h挂了好久发现二分写挂了……对于\(\min\{a_i\}\)这一部分,不难想到找到当前\(\min\{a_i\}\)的位置计算其左右两......
  • AtCoder Beginner Contest 287
    FComponents考虑树形\(DP\)。有\(f_{i,j,0/1}\)为以\(i\)为根的子树,一共有\(j\)个连通块,选/不选的方案数。\[pre_{x,0/1}\leftarrowf_{u,x,0/1}\]\[f_......
  • AtCoder Beginner Contest 285
    C:abc285_brutmhyhiizp题目大意一串序列A,B,...,Z,AA,AB,...,ZZ,AAA,...给定一个字符串求在序列中的排名(保证存在)思路将每个A看作\(1\),B看作\(2\),....,Z......
  • (AtCoder Beginner Contest 287)(D 字符串前后缀合并匹配)(E Trie求最长公共前缀(LCP)
    D-MatchorNot(字符串前后缀合并匹配)题目大意:给定两个字符串S和T,对于每个x=0,1,2...|T|求S的子串(前x个字符和后|T|-x个字符在不改变顺序的情况下组成)是否与T相......
  • 【字典树】Atcoder Beginner Contest 287----E
    题目:E-Karuta(atcoder.jp)题解:这道题就是一个字典树求最长公共前缀的板子题。可以直接交板子。但我在翻题解的时候发现了另一种思路,就是将字符串按字典序排列后,每一个......
  • AtCoder Beginner Contest 287 解题报告
    AtCoderBeginnerContest287解题报告\(\text{ByDaiRuiChen007}\)ContestLinkA.Majority用map分别统计两种字符串出现的次数并与\(\left\lfloor\dfracn2\righ......
  • AtCoder Beginner Contest 287
    A-Majority(abc287a)题目大意给定\(n\)个人对某个提案的意见,问大多数意见是支持还是反对解题思路统计比较即可。神奇的代码#include<bits/stdc++.h>usingnam......