题号:图的遍历
#include<iostream>
#include<vector>
using namespace std;
const int maxn = 100010;
vector<int> grap[maxn];
int A[maxn]={0};
void dfs(int x,int d){
if(A[x])return;
A[x] = d;
for(int i = 0;i<grap[x].size();i++){
dfs(grap[x][i],d);//这个d永远不变,都是最大的
}
}
int main(){
int N,M;
cin>>N>>M;
for(int i = 0;i<M;i++){
int n,m;
cin>>n>>m;
grap[m].push_back(n);//顺序交换,将大的换入到小号中
}
for(int i = N;i>0;i--){
dfs(i,i);
}
for(int i =1;i<=N;i++){
cout<<A[i]<<" ";
}
}
标签:遍历,int,dfs,grap,maxn,include
From: https://www.cnblogs.com/tsqo/p/16943419.html