zoukankan
html css js c++ java
HDU1325 Is It A Tree?
/*不能算是并查集,只是用了路径压缩和树的特点, 和1272的区别在于它是有向图,它的父结点是固定的*/ #include <iostream> using namespace std; int main() { int n,m,k=0,s[100005]={0},j=0,i,big; bool f=0; bool flag[100005]={0}; while(cin>>n>>m) { if(m==-1&&n==-1)return 0; if(m==0&&n==0) { k++; int c=0; for(i=1;i<=big;i++){if(flag[i]){c++;flag[i]=0;s[i]=0;}} if(f) cout<<"Case "<<k<<" is not a tree."<<endl; else if(c==0)cout<<"Case "<<k<<" is a tree."<<endl; else if(c!=j+1)cout<<"Case "<<k<<" is not a tree."<<endl; else cout<<"Case "<<k<<" is a tree."<<endl; j=0; f=0; big=0; } else { j++; flag[n]=flag[m]=1; if((m>n?m:n)>big)big=(m>n?m:n); //如果已经有父结点,但是父结点不是n,那就是不树了 if(s[m]!=0&&s[m]!=n)f=1; else s[m]=n; } } return 0; }
查看全文
相关阅读:
什么是交互式?
python之禅
爬虫保存cookies时重要的两个参数(ignore_discard和ignore_expires)的作用
PL/0编译器(java version) – Symbol.java
PL/0编译器(java version) – Scanner.java
PL/0编译器(java version)–Praser.java
PL/0编译器(java version)–PL0.java
PL/0编译器(java version)–Pcode.java
PL/0编译器(java version)
PL/0编译器(java version)
原文地址:https://www.cnblogs.com/windmissing/p/2559865.html
最新文章
物理引擎
Ogre场景编辑器Ogitor源代码的构建
Ogre的Singleton实现-模版实现,便于重用-(详细分析)以及笔者的改进
编程风格
Module 的加载实现
Module 的语法
Class 的继承
Class 的基本语法
async 函数
Generator 函数的异步应用
热门文章
Generator 函数的语法
Iterator 和 for...of 循环
Promise 对象
水平居中,垂直居中,显示
f
python 私有方法
python json相关问题
抽象类
散列
数组和列表
Copyright © 2011-2022 走看看