but It's my first time to CII...I'm still a green hand here
So there are so many problems occur to me...
At first, I failed with verdict Compile Error...I have never meet with this SURPRISING problem...unbelievable (I use G++ as my compiler)
and then,my code run into Runtime Error and never get out...
I can't really figure out what the real problems is...
could any help me out?
Here is my algorithm:
everytime I enum the nodes with indegree==0 and then DFS it...
delete every edges it covered...
then comes with my CODE...
any help will does...
Thanks in advance...
- Code: Select all
#include<iostream>
#include<cstdio>
#include<vector>
#define MAXN 110
using namespace std;
vector<int> vi[MAXN],key[MAXN];
int n,id[MAXN],od[MAXN],tmpod[MAXN],g[MAXN][MAXN];
void dfs(int var,int u,int cur)
{
g[var][cur]=u;
if(od[u]<=0)
return ;
--od[u];
for(int i=0;i<tmpod[u];++i)
{
int v=vi[u][i];
if(id[v]>0)
{
--id[v];
dfs(var,v,cur+1);
return ;
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
#endif
while(scanf("%d",&n)!=EOF && n)
{
int i,j,t;
memset(id,0,sizeof(id));
memset(g,0,sizeof(g));
for(i=1;i<=n;++i)
{
vi[i].clear();
scanf("%d",od+i);
tmpod[i]=od[i];
for(j=0;j<od[i];++j)
{
scanf("%d",&t);
++id[t];
vi[i].push_back(t);
}
}
int ans=0;
while(true)
{
bool next=false;
for(i=1;i<=n;++i)
if(!id[i] && od[i]>0)
{
dfs(ans++,i,0);
next=true;
break;
}
if(!next)
break;
}
printf("%d\n",ans);
for(i=0;i<ans;++i)
{
printf("%d",g[i][0]);
j=1;
while(g[i][j])
printf(" %d",g[i][j++]);
putchar('\n');
}
}
return 0;
}
