ZOJ4116 Game on a Graph

给一个含n个点 m条边的连通图 把k个人分成两组 轮流拿掉一条边 当取走一条边后图不再连通 这个队就输了

水题啦 边为n-1时 下一个拿掉边的那个组就输啦

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef unsigned long long ull;
 5 int main(){
 6     ll t, k, n, m, u, v;
 7     char s[100005];
 8     cin>>t;
 9     while (t--){
10         memset(s, 0, sizeof(s));
11         cin>>k;
12         cin>>s;
13         cin>>n>>m;
14         for (int i = 0; i < m; i++) cin>>u>>v;
15         if (m - n + 1 > 0){
16             if (s[(m - n + 1) % k] == '1') cout<<2<<endl;
17             else if (s[(m - n + 1) % k] == '2') cout<<1<<endl;
18         }
19         else{
20             if (s[0] == '1') cout<<2<<endl;
21             else if (s[0] == '2') cout<<1<<endl;
22         }
23     }
24     return 0;
25 }

猜你喜欢

转载自www.cnblogs.com/Misuchii/p/10897026.html