發表文章

目前顯示的是 九月 23, 2012的文章

SPOJ Problem 1436: Is it a tree – PT07Y

C++ code colored by C++2HTML#include <cstdlib> #include <iostream> #include <list> #include <stdio.h> #include <string.h> using namespace std; list<int> al[10001]; int ii, jj, node[10001]; long long int nn, magic_tri=2; bool no; void tt(int start_node, int pri_node) { node[start_node] = magic_tri; if(false == no) { list<int>::iterator it; for(it=al[start_node].begin() ; it != al[start_node].end(); it++ ) { if(*it == start_node)continue; if(*it == pri_node)continue; if(node[*it] == magic_tri) { no = true; break; } else { jj = *it; tt(jj, start_node); } } } } int main() { int ee, n1, n2; while(cin>>nn>>ee) { for(ii=0;ii<nn;++ii) { al[ii].clear(); } for(ii=0;i…