我想蒻蒻的问一句
```cpp
memset(first,1,sizeof(-1));
```
这个是什么意思。
by 冥诺在线发呆 @ 2019-07-17 21:59:35
@[冥诺在线发呆](/space/show?uid=210921) ~~就当我什么都没发~~
by 没有输入 @ 2019-07-17 22:13:12
```cpp
#include<bits/stdc++.h>
using namespace std;
int first[100005],next[100005],n,m,u[100005],v[100005],ans;
void dfs(int k)
{
if(k==-1) return;
ans=max(ans,max(u[k],v[k]));
dfs(next[k]);
}
int main()
{
memset(first,-1,sizeof(first));
scanf("%d%d",&n,&m);
for(int i=1; i<=m; i++)
{
scanf("%d%d",&u[i],&v[i]);
next[i]=first[u[i]];
first[u[i]]=i;
}
for(int i=1; i<=n; i++)
{
ans=0;
dfs(first[i]);
printf("%d ",ans);
}
return 0;
}
```
那现在呢?![](https://cdn.luogu.com.cn/upload/pic/64291.png)
by 没有输入 @ 2019-07-17 22:22:27
@[没有输入](/space/show?uid=154344)
```cpp
for(int i=1; i<=m; i++)
{
scanf("%d%d",&u[i],&v[i]);
next[i]=first[u[i]];
first[u[i]]=i;
}
```
话说你这里v[i]没用到?
by 冥诺在线发呆 @ 2019-07-18 21:48:26
@[冥诺在线发呆](/space/show?uid=210921) 这不是邻接表模板吗?
by 没有输入 @ 2019-07-18 21:53:28
@[冥诺在线发呆](/space/show?uid=210921) [邻接表](https://bbs.codeaha.com/thread-4612-1-1.html)
by 没有输入 @ 2019-07-18 21:56:37
应该是
```cpp
for(int i=1; i<=m; i++)
{
scanf("%d%d",&u[i],&v[i]);
next[i]=first[v[i]];
first[u[i]]=i;
}
```
by 冥诺在线发呆 @ 2019-07-18 22:03:34
@[没有输入](/space/show?uid=154344) 还有,要设一个vis数组,因为可能有环
by 冥诺在线发呆 @ 2019-07-18 22:04:34
![](https://cdn.luogu.com.cn/upload/pic/64489.png)
这……你确定?
by 没有输入 @ 2019-07-18 22:14:42
@[冥诺在线发呆](/space/show?uid=210921) vis数组确实是我没考虑到,但是这个邻接表……
by 没有输入 @ 2019-07-18 22:15:32