社区讨论
20tps,全TLE,玄关
P5318【深基18.例3】查找文献参与者 4已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @mhjupuim
- 此快照首次捕获于
- 2025/11/04 08:49 4 个月前
- 此快照最后确认于
- 2025/11/04 08:49 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
vector<pair<int , int> > v;
queue<int> q;
bool vis[100010] , vis1[100010];
int n , m;
void dfs(int x){
if(vis[x] == 1) return;
vis[x] = 1;
cout << x << " ";
for(int i = 0; i < m; i++){
if(x == v[i].first){
dfs(v[i].second);
}
}
}
int main(){
cin >> n >> m;
for(int i = 1; i <= m; i++){
int a , b;
cin >> a >> b;
v.push_back(make_pair(a , b));
}
sort(v.begin() , v.end());
dfs(1);
q.push(1);
cout << endl;
while(!q.empty()){
cout << q.front() << " ";
int qtop = q.front();
q.pop();
for(int i = 0; i < m; i++){
if(qtop == v[i].first and vis1[v[i].second] == 0){
vis1[v[i].second] = 1;
q.push(v[i].second);
}
}
}
}
那很坏了
回复
共 5 条回复,欢迎继续交流。
正在加载回复...