D - Game on a Graph

水深无声 2022-01-30 08:09 285阅读 0赞

在这里插入图片描述

Output

For each test case output one line containing one integer. If the 1st group wins, output “1” (without quotes); If the 2nd group wins, output “2” (without quotes).

Sample Input

3
5
11212
4 6
0 1
0 2
0 3
1 2
1 3
2 3
5
11121
5 7
0 2
1 3
2 4
0 3
1 2
3 2
4 1
3
121
4 3
0 1
0 2
1 3

Sample Output

2
1
2

题意:给你一个连通图,按照给定的次序开始割边,谁先让图不连通谁就输了,给定的次序可以循环(这个地方当时没读懂,就gg了)。

思路,不用看连通图的位置,只需要看他有几个点几条边就行,如果把一个连通图分开,把他的边割到n-1条。分析它的必败态,如果割到了只剩下 n-1条边(n个点) 这个时候轮到谁割谁就输。如果边的条数正好等于n-1条,那么谁第一个割,谁就必败。本题结束。

AC代码:

  1. #include<iostream>
  2. using namespace std;
  3. typedef long long ll;
  4. int main()
  5. {
  6. ll t;
  7. cin>>t;
  8. while(t--)
  9. {
  10. ll k,n,m;
  11. string s;
  12. cin>>k;
  13. cin>>s;
  14. cin>>n>>m;
  15. for(int i=0;i<m;i++)
  16. {
  17. ll l,r;
  18. cin>>l>>r;
  19. }
  20. if(n>m)
  21. {
  22. if(s[0]=='1')
  23. cout<<"2"<<endl;
  24. else
  25. cout<<"1"<<endl;
  26. continue;
  27. }
  28. ll num=(m-n+1)%k;
  29. if(s[num]=='1')
  30. cout<<"2"<<endl;
  31. else
  32. cout<<"1"<<endl;
  33. }
  34. return 0;
  35. }

发表评论

表情:
评论列表 (有 0 条评论,285人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CF165D Beard Graph

    [题目链接][Link 1] 树剖题不用多说,一开始所有黑边的权值是-1,若有修改白边的操作,就把白边的值赋为100000。 之后查询边权之和时,如果和大于1000000,