社区讨论
帮我看看我的帖子,怎么过不了啊
P5318【深基18.例3】查找文献参与者 3已保存回复 6
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @m2kgx5t6
- 此快照首次捕获于
- 2024/10/22 21:15 去年
- 此快照最后确认于
- 2025/11/04 16:30 4 个月前
CPP
#include<bits/stdc++.h>
#define maxn 1000000
using namespace std;
int n,m;
vector<int>p[maxn];
queue<int>q;
bool b[maxn];
void dfs(int a) {
cout<<a<<" ";
for(int i=0,sz=p[a].size(); i<sz; i++) {
if(!b[p[a][i]]) {
b[p[a][i]]=true;
dfs(p[a][i]);
}
}
}
void bfs(int a) {
q.push(1);
while(!q.empty()) {
int x=q.front();
q.pop();
for(int i=0,sz=p[x].size(); i<sz; i++) {
if(!b[p[x][i]]) {
b[p[x][i]]=true;
q.push(p[x][i]);
}
}
cout<<x<<' ';
}
}
int main() {
cin>>n>>m;
for(int i=1; i<=m; i++) {
int x,y;
cin>>x>>y;
p[x].push_back(y);
}
b[1]=true;
bfs(1);
cout<<endl;
dfs(1);
return 0;
}
各位神犇帮我看看,谢谢啦
回复
共 6 条回复,欢迎继续交流。
正在加载回复...