HDU 3094 无向图的删边游戏
2014-10-18 11:21
162 查看
第一道删边题,这大概是博弈最后一个没有熟悉的分支了
//HDU-3094.cpp #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <ctime> #include <climits> #include <cctype> #include <algorithm> #include <iostream> #include <string> #include <stack> #include <map> #include <set> #include <queue> #include <utility> #include <vector> #include <bitset> #include <functional> using namespace std; //const double pai = acos(-1.0); const double pai = 3.14159265358979323846; const int INF = 0x3f3f3f3f; typedef long long love_live; int sg[100117]; bool mex[100117]; vector<int> arr[100117]; void init(){ memset(mex, 0, sizeof(mex)); memset(sg, -1, sizeof(sg)); return ; } int getsg(int x){ if(sg[x] != -1){ return sg[x]; } int i, j, k; sg[x] = 0; mex[x] = 1; for(i = 0; i < arr[x].size(); ++i){ if(mex[arr[x][i]] == 0){ sg[x] ^= (getsg(arr[x][i]) + 1); } } mex[x] = 0; return sg[x]; } int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE // freopen("output", "w", stdout); freopen("input", "r", stdin); #endif int n, m, i, j, k; int t, a, b; while(scanf("%d", &t) != EOF){ while(t--){ scanf("%d", &n); for(i = 0; i <= n; ++i){ arr[i].clear(); } for(i = 1; i < n; ++i){ scanf("%d %d", &a, &b); arr[a].push_back(b); arr[b].push_back(a); } init(); if(getsg(1) == 0){ printf("Bob\n"); } else{ printf("Alice\n"); } } } return 0; }
相关文章推荐
- hdu 3094 树的删边游戏
- HDU 3094 A tree game 树的删边游戏
- HDU 3094 A tree game 树删边游戏
- HDU 3094 A tree game(树上删边游戏)
- hdu 3094 A tree game (树形删边游戏)
- HDU 5299 Circles Game(树的删边游戏)
- HDU 3904 A tree game(树的删边游戏,树形图博弈)
- HDU 2176 取(m堆)石子游戏
- HDU 2516 取石子游戏
- HDU 2177 取(2堆)石子游戏
- hdu 4315 Climbing the Hill 博弈问题,可转化为nim游戏问题,多校联合赛(二)第六题
- HDU A simple stone game [K倍动态减法游戏]
- 杭电hdu 1527 取石子游戏 Wythoff Game 博弈
- hdu 2516 取石子游戏
- HDU 2174 取(m堆)石子游戏
- hdu 1281【棋盘游戏】
- hdu 棋盘游戏 (求二分图最大匹配的关键点)
- hdu 2176 取(m堆)石子游戏
- HDU 2209 翻纸牌游戏
- HDU 1527 取石子游戏