[BZOJ 1603]打谷机
转载请注明出处:http://danihao123.is-programmer.com/
啊啊啊啊我又活过来了……
然而这也就是一道脑残题……
代码:
/************************************************************** Problem: 1603 User: danihao123 Language: C++ Result: Accepted Time:20 ms Memory:820 kb ****************************************************************/ #include <cstdio> #include <cstring> #include <vector> using namespace std; const int maxn=1001; struct Edge{ int u,v; bool type; }; vector<Edge> edges; vector<int> G[maxn]; void Add_Edge(int u,int v,bool type){ edges.push_back((Edge){u,v,type}); G[u].push_back(edges.size()-1); } bool ans[maxn],vis[maxn]; void dfs(int x){ vis[x]=true; int i; for(i=0;i<G[x].size();i++){ Edge& e=edges[G[x][i]]; if(!vis[e.v]){ ans[e.v]=e.type?(!ans[x]):ans[x]; dfs(e.v); } } } int main(){ register int i; int n,u,v,d; scanf("%d",&n); for(i=0;i<(n-1);i++){ scanf("%d%d%d",&u,&v,&d); Add_Edge(u,v,(bool)d); Add_Edge(v,u,(bool)d); } dfs(1); printf("%d\n",ans[n]?1:0); return 0; }