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 |
Re:天啦,给偶块豆腐让偶去撞死吧,大牛请来相帮In Reply To:天啦,给偶块豆腐让偶去撞死吧,大牛请来相帮 Posted by:Pzjay at 2009-10-15 16:48:25 //by David #include "cstdlib" #include "cctype" #include "cstring" #include "cstdio" #include "cmath" #include "algorithm" #include "vector" #include "string" #include "iostream" #include "sstream" #include "set" #include "queue" #include "stack" #include "fstream" #include "strstream" using namespace std; typedef __int64 LL; //scanf("%I64d", &x); typedef vector<int> VI; typedef pair<int,int> PII; #define MP make_pair #define FOR(i,a) for( int i = 0 ; i < a ; i ++ ) #define LL(a) a<<1 //a=a*2 LL和RR主要用于线段树 #define RR(a) a<<1|1 //a=a*2+1 const double Pi = acos(-1.0); template<class T> inline void checkmmin(T &a,T b) {if(a < 0 || a > b)a = b;} template<class T> inline void checkmax(T &a,T b) {if(a < b) a = b;} int dx[] = {-1,0,1,0,1,1,-1,-1};//up Right down Left int dy[] = {0,1,0,-1,1,-1,1,-1};//复制strcpy和strncpy //strstr查找子串;strrev对字符串反序 //strncpy后加'\0' //----------------------------------------------------------------- #define N 100 int main() { int a,b; int Case=1; int p[N]; bool arr[N]; int i,j; while(scanf("%d%d",&a,&b)!=EOF) { if(a==-1 && b==-1)break; memset(p,0,sizeof p); memset(arr,0,sizeof arr); int f=0; while(a||b) { if(p[b]!=0 || a==b) f=1; p[b]=a; arr[b]=1; scanf("%d%d",&a,&b); } if(!f) { int r,t; for(r=0;r<N;r++) if(arr[r]) break; t=r; while(p[r]) { r=p[r]; if(t==r) {f=1;break;} } for(i=0;i<N;i++) if(arr[i]) { j=i; t=j; while(p[j]) { j=p[j]; if(t==j) {f=1;break;} } if(j!=r || f==1) { f=1;break; } } } if(f) printf("Case %d is not a tree.\n",Case++); else printf("Case %d is a tree.\n",Case++); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator