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 |
这也能超内存?求教#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 51000 #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 node { int tar; struct node* next; }Link; int fa[MXX]; int times[MXX],n,m,step,c[MXX],done[MXX]; Link he[MXX],he1[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; } Link *op; Link *F; void tanjar(int H) { fa[H]=H; Link *K=&he[H]; while(K->next) { K=K->next; tanjar(K->tar); fa[K->tar]=H; } K= &he1[H] ; while ( K->next) { K=K->next; if (done[K->tar]) { int anc = find(K->tar) ; times[anc] ++ ; } else { op=&he1[K->tar]; F=(Link*)malloc(sizeof(Link)); F->tar=H; F->next=op->next; op->next=F; } } done[H]=1; } int main() { int i,temp1,a,b,T,sum,marko,temp2,temp3; while(scanf("%d",&n)!=EOF) { Link* K; Link *A; for(i=1;i<=n;i++) { scanf("%d:(%d)",&temp1,&temp2); K=&he[temp1]; K->next=NULL; for(int j=1;j<=temp2;j++) { scanf("%d",&temp3); c[temp3]=1; A=(Link*)malloc(sizeof(Link)); A->tar=temp3; A->next=K->next; K->next=A; } } scanf("%d\n",&m); for(i=0;i<m;i++) { while(getchar() != '('){} scanf("%d%d",&temp1,&temp2); K=&he1[temp1]; A=(Link*)malloc(sizeof(Link)); A->tar=temp2; A->next=K->next; K->next=A; 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(he,0,sizeof(he)); memset(he1,0,sizeof(he1)); 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