Weighings sgu-230
Question:
Give you a directed graph of n points and m edges, and then ask you to find a path that goes through all vertices. The output vertex I is the first vertex.
Solution:
It took me a long time to understand this question. After all, it is difficult to understand English .....
A very watery question is just sorting the topology. There is nothing to talk about...
AC code:
#include
#include
#include
#include #include
#include
#define MAX(a,b) ((a)>(b)?(a):(b))#define MIN(a,b) ((a)>(b)?(b):(a))using namespace std;int n,m;struct bian_{int next;int num;}bian[10010]={{0,0}};int First[110]={0};int hash[110]={0};int du[110]={0};inline void Add(int p,int q,int k){bian[k].next=First[p];bian[k].num=q;First[p]=k;return;}int main(){scanf("%d%d",&n,&m);for(int i=1;i<=m;i++){int p,q;scanf("%d%d",&p,&q);Add(p,q,i);du[q]++;}int dui[110]={0};int duip=0;for(int i=1;i<=n;i++)if(du[i]==0) dui[++duip]=i;for(int i=1;i<=duip;i++){int u=dui[i];for(int p=First[u];p!=0;p=bian[p].next){du[bian[p].num]--;if(du[bian[p].num]==0)dui[++duip]=bian[p].num;}}if(duip