40 pts mle
  • 板块P3916 图的遍历
  • 楼主yyjw14
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/10/3 08:07
  • 上次更新2023/11/2 16:24:52
查看原帖
40 pts mle
916380
yyjw14楼主2023/10/3 08:07
#include<bits/stdc++.h>
using namespace std;
vector <int > edge[100005];
bool vis[100005];
int ms=0;
void dfs(int x)
{
	if(vis[x]==1)return;
	vis[x]==1;
	if(x>=ms)
    {
        ms=x;
    }
    for(auto y:edge[x])
    {	
		dfs(y); 	
    }
}
int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int i,j,k,u,v;
    cin>>i>>j;
    for(k=1;k<=j;k++)
    {
        cin>>u>>v;
        if(u!=v)
		{
			edge[u].push_back(v);
			//vis[u][v]=1;
		}	
    }
    for(k=1;k<=i;k++)
    {
		ms=0;
        dfs(k);
        cout<<ms<<" ";
    }
}
2023/10/3 08:07
加载中...