8652: If You Can't Beat Them, Join Them!

内存限制:512 MB 时间限制:12 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

Roundgod and kimoyami are playing the graph game on a directed graph. Given a directed graph G=(V,E)G=(V,E) and a source vertex s\in VsV, the graph game (G,s) is defined as follows:

  1. Initially, there is a token on the source vertex s. Roundgod and kimoyami take turns moving the token through a directed edge, with Roundgod going first. The game ends when either player cannot make a valid move, and the player who cannot make a move loses. If the game lasts 10100 turns, then the game is considered a draw.

Roundgod is not an expert at this game and is often beaten by kimoyami. He remembered the famous quote, "If you can't beat them, join them!'', and then came up with the notion of join of graph games.
Given a nonempty collection of k(k>0) graph games (G1,s1),,(Gk,sk). The join of the kk games is also a game with the following definition:

  1. Roundgod and kimoyami take turns moving the tokens in all kk graph games simultaneously, with Roundgod going first. The game ends when either player cannot make a valid move in any of the kgames, and the player who cannot make a move loses. If the game lasts 10100 turns, then the game is considered a draw.

Now, given a collection of k graph games, (G1,s1),,(Gk,sk), Roundgod then needs to choose a nonempty subset from the k games and play with kimoyami on the join of the chosen games. Roundgod wonders, how many ways are there to choose such a nonempty subset so that he may win the game under the optimal strategy of both players? As the answer may be too large, you need to output the answer modulo 998244353

输入格式

The first line contains an integer T(1T5), denoting the number of test cases.

For each test case, the first line of the input contains an integer k(1k106), denoting the number of graph games in the collection.

Then the description of k graph games follows.

For the description of the i(1ik)-th graph game, the first line contains three integers ni,mi,si(1ni,mi106,1sini), denoting the number of vertices and edges of in the graph of the ith graph game, and the source vertex of the ith graph game, respectively.

Then mi lines follow, each line contains two integers u,v(1u,vni,u!=v), denoting an edge in the graph of the ith graph game. Note that it is possible for the graph to have multiple edges, but not self loops.

It is guaranteed that for each test casei=1kni2×106 and i=1kmi2×106

输出格式

Output an integer in a line, denoting the answer taken modulo 998244353

输入样例 复制

2
1
4 3 1
1 2
1 3
3 4
3
2 2 1
1 2
2 1
2 1 1
1 2
2 1 2
1 2

输出样例 复制

1
2