#include <vector> using namespace std; #include<iostream> #include <cstdio> #include <cstring> #define maxn 200005 struct Edge { int v,next; }edge[maxn]; int head[maxn]; int cnt; void addedge(int u,int v) { edge[cnt].v=v; edge[cnt].next=head[u]; head[u]=cnt; cnt++; } int main() { int n,m; memset(head,-1,sizeof head); cin>>n>>m; for(int i=1;i<=m;++i) { int u,v; cin>>u>>v; addedge(u,v); } int x; cin>>x; for(int i=head[x];i!=-1;i=edge[i].next) { printf("%d->%d\n",x,edge[i].v); } return 0; }
原文:https://www.cnblogs.com/zzyf/p/13392611.html