MLE 0tps 玄关
查看原帖
MLE 0tps 玄关
1050776
peterJr楼主2024/6/10 19:40
#include <stdio.h>

const int MAXN = 1e5 + 7, MAXM = 1e5 + 10;
int n, m, from[MAXM], to[MAXN], nxt[MAXM], ans, tot;

inline void add(const int& u, const int& v)
{
	nxt[++tot] = from[u];
	to[tot] = v;
	from[u] = tot;
}

void dfs(int k, int curr)
{
	if (k > curr) curr = k;
	ans = curr;
	for (int i = from[k]; i; i = nxt[i])
	{
		int y = to[i];
		dfs(y, curr);
	}
}

main()
{
	scanf("%d %d", &n, &m);
	for (int i = 1, u, v; i <= m; ++i)
	{
		scanf("%d %d", &u, &v);
		add(u, v);
	}
	
	for (int i = 1; i <= n; ++i)
	{
		ans = 0;
		dfs(i, i);
		printf("%d ", ans);
	}
	
	return 0;
}
2024/6/10 19:40
加载中...