#include <stdio.h>
#include <malloc.h>
#include <string.h>
using namespace std;
#define maxven 20
bool visited[100]={0};
int in[100]={0},out[100]={0},total[100];
typedef struct ArcNode
{ int adjvex;
struct ArcNode *next;
} ArcNode;
typedef struct VNode
{ int data;
ArcNode *firstarc;
} VNode;
typedef struct
{ int n,e;
VNode adjlist[maxven];
}Graph;
void Dispgra(Graph G)
{
int i;
ArcNode *p;
for (i=0;i<G.n;i++)
{
printf("%d:",G.adjlist[i].data);
p=G.adjlist[i].firstarc;
while (p!=NULL)
{ printf("%d ",p->adjvex);
p=p->next;
}
printf("\n");
}
}
void DFS(Graph G,int x)
{
int i,j;
printf("v%d ",x+1);
visited[x]=1;
ArcNode *p;
p=G.adjlist[x].firstarc;
while(p)
{
if(!visited[p->adjvex-1])
DFS(G,p->adjvex-1);
p=p->next;
}
}
void BFS(Graph G,int x)
{
int bf[maxven],i,v;
int front=0,rear=0;
printf("v%d ",x+1);
rear=(rear+1)%maxven;
bf[rear]=x;visited[x]=1;
ArcNode *p;
while(rear!=front)
{
front=(front+1)%maxven;
v=bf[front];
p=G.adjlist[v].firstarc;
while(p)
{
if(!visited[p->adjvex-1])
{
printf("v%d ",p->adjvex);
visited[p->adjvex-1]=1;
rear=(rear+1)%maxven;
bf[rear]=p->adjvex-1;
}
p=p->next;
}
}
}
void buildgraph( Graph &G)
{
int i,j,x,y;
ArcNode *p,*q;
scanf("%d%d",&G.n,&G.e);
for (i=0;i<G.n;i++)
{
scanf("%d",&G.adjlist[i].data);
G.adjlist[i].firstarc=NULL;
}
for(i=0;i<G.e;i++)
{
scanf("%d%d",&x,&y);
out[x-1]++;in[y-1]++;
p=(ArcNode *)malloc(sizeof(ArcNode));
p->adjvex=y;
p->next=G.adjlist[x-1].firstarc;
G.adjlist[x-1].firstarc=p;
q=(ArcNode *)malloc(sizeof(ArcNode));
q->adjvex=x;
q->next=G.adjlist[y-1].firstarc;
G.adjlist[y-1].firstarc=q;
}
for(i=0;i<G.n;i++)
total[i]=out[i]+in[i];
}
void outdu(int in[],int out[],int total[],int n)
{
int i;
for(i=0;i<n;i++)
printf("%d:%d %d %d\n",i+1,in[i],out[i],total[i]);
}
int main()
{
int i,j,x,y;
Graph G;
//buildgraph(G);
//Dispgra(G);
//DFS(G,0);
//BFS(G,0);
//outdu(in,out,total,G.n);
return 0;
}