Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
若此清晰MLE#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <numeric> #include <utility> #include <iostream> #include <iomanip> #include <cstring> #include <ctime> #include<stdio.h> #include<string.h> #include<math.h> using namespace std; const double pi=acos(-1.0); const double eps=1e-11; #define MXX 950 #define INF ((1<<31)-5) #define two(X) (1<<(X)) #define contain(S,X) (((S)&two(X))!=0) #define PB(X) push_back(X) #define SIZE(X) ((int)(X.size())) #define LENGTH(X) ((int)(X.length())) queue<int> EM; typedef struct Anode { int tar; struct Anode *next; }Anode; typedef struct Vnode { Anode * first; }Vnode; void ADD(Vnode *he,int u,int v) { Anode *p; p=(Anode*)malloc(sizeof(Anode)); p->tar=v; p->next=he[u].first; he[u].first=p; } Vnode he1[MXX],he2[MXX]; int k,done[MXX],fa[MXX],times[MXX],c[MXX]; int find(int H) { return H==fa[H]?H:fa[H]=find(fa[H]); } void U(int a,int b) { a=find(a); b=find(b); if(a!=b) fa[a]=b; } void tanjar(int H) { fa[H]=H; Anode *ko; Anode *ok; ko=he1[H].first; while(ko!=NULL) { tanjar(ko->tar); fa[ko->tar]=H; ko=ko->next; } ok=he2[H].first; done[H]=1; while(ok!=NULL) { if(done[ok->tar]) { int anc = find(ok->tar) ; times[anc] ++ ; } ok=ok->next; } } int main() { int i,temp1,a,b,T,sum,marko,temp2,temp3,n,m; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) { he1[i].first=0; } for(i=1;i<=n;i++) { scanf("%d:(%d)",&temp1,&temp2); for(int j=1;j<=temp2;j++) { scanf("%d",&temp3); c[temp3]=1; ADD(he1,temp1,temp3); } } k=1; scanf("%d\n",&m); for(i=0;i<m;i++) { while(getchar() != '('){} scanf("%d%d",&temp1,&temp2); ADD(he2,temp1,temp2); ADD(he2,temp2,temp1); while(getchar() != ')') {} } int root; for(i=1;i<=n;i++) { if ( !c[i] ) { root=i ; break ; } } tanjar(root); for(i=1;i<=n;i++) if(times[i]!=0) printf("%d:%d\n",i,times[i]) ; memset(he1,0,sizeof(he1)); memset(he2,0,sizeof(he2)); memset(c,0,sizeof(c)); memset(done,0,sizeof(done)); memset(times,0,sizeof(times)); memset(fa,0,sizeof(fa)); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator