| ||||||||||
| 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 | |||||||||
请高手指教!WA了N次了.#include <iostream>
using namespace std;
int main()
{ int nodecount;
int check[1000][2],flag[1000][2];
int countX(0),countY(0);
int pointX,pointY,number(0);
int i,j;
cin >> pointX >> pointY;
while(pointX>0||pointY>0)
{ int judge(0);
while( pointX != 0 || pointY != 0)
{
flag[countX][0]=0;
flag[countY][1]=0;
check[countX++][0] = pointX;
check[countY++][1] = pointY;
cin >> pointX >> pointY;
}
nodecount=2*countX;
for( i = 0 ; i < countX ; ++i)
{
for( j = i+1 ; j < countX ; ++j)
{
if( (check[i][1] == check[j][1] && check[i][0] != check[j][0])|| (check[i][1] == check[j][0]&&check[i][0] == check[j][1]) ||(check[i][0] == check[i][1]) )
{
judge = 1;
break;
}
if(i != j && check[i][0] == check[j][0] && check[i][1]==check[j][1])
{
judge = 1;
break;
}
}
if(judge) break;
}
for(i = 0 ; i < countX ; ++i)
{
for(j = i+1 ; j < countX ; ++j)
{ if(check[i][0]==check[j][0])
flag[j][0]=-1;
if(check[i][0]==check[j][1])
flag[j][1]=-1;
if(check[i][1]==check[j][0])
flag[j][0]=-1;
}
}
for(i=0;i<countX;i++)
{ if(flag[i][0]==-1)
nodecount--;
if(flag[i][1]==-1)
nodecount--;
}
if(nodecount!=countX+1)
judge=1;
if(judge)
cout << "Case "<< ++number <<" is not a tree."<<endl;
else
cout << "Case " << ++number << " is a tree."<<endl;
cin >> pointX >> pointY;
countX=0;
countY=0;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator