A little modification on the basis of HDU 1272 AC
1272 have been judged whether the tree structure is not in the case, so we just need to judge the degree of 0 of the point whether only one is good
#include <iostream> #define MAXN 100000+5using namespace Std;int a,b;int flag;int father[maxn];int sign[maxn];int R [Maxn];void Ready () {for (int i=1;i<maxn;i++) r[i]=0,father[i]=i,sign[i]=0;} int dfs (int x) {if (father[x]!=x) {father[x]=father[father[x]];} return father[x];} void build (int x,int y) {if (x==y) flag=0;else{if (DFS (x) ==dfs (y)) Flag=0;else{father[dfs (x)]=dfs (y);}} r[y]++;} int main () {int Casee=1;while (cin>>a>>b) {ready (), flag=1;if (a<0&&b<0) {break;} if (!a&&!b) {cout<< "case" <<casee++<< "is a tree." <<endl;continue;} Build (A, b); Sign[a]=sign[b]=1;while (cin>>a>>b&&a&&b) {build (A, b); sign[a]=sign[b]=1;} int k=0,d=0;for (int i=1;i<maxn;i++) {if (Sign[i]&&dfs (i) ==i) k++;if (sign[i]&&r[i]==0) d++;} if (k==1&&flag&&d==1) cout<< "case" <<casee++<< "is a tree." <<endl;else cout<< "Case" <<casee++<< "was not a tree." <<endl;} return 0;}
HDU 1325 is It A Tree?