As we all know, Aryan is a funny guy. He decides t...

創建於:2025年6月21日

使用 O4 Mini High 回答 Chat01

問題

As we all know, Aryan is a funny guy. He decides to create fun graphs. For a graph GG, he defines fun graph GG' of GG as follows:

  • Every vertex vv' of GG' maps to a non-empty independent set^{\text{∗}} or clique^{\text{†}} in GG.
  • The sets of vertices of GG that the vertices of GG' map to are pairwise disjoint and combined cover all the vertices of GG, i.e., the sets of vertices of GG mapped by vertices of GG' form a partition of the vertex set of GG.
  • If an edge connects two vertices v1v_1' and v2v_2' in GG', then there is an edge between every vertex of GG in the set mapped to v1v_1' and every vertex of GG in the set mapped to v2v_2'.
  • If an edge does not connect two vertices v1v_1' and v2v_2' in GG', then there is not an edge between any vertex of GG in the set mapped to v1v_1' and any vertex of GG in the set mapped to v2v_2'.

As we all know again, Harshith is a superb guy. He decides to use fun graphs to create his own superb graphs. For a graph GG, a fun graph G' ' is called a superb graph of GG if G' ' has the minimum number of vertices among all possible fun graphs of GG.

Aryan gives Harshith kk simple undirected graphs^{\text{‡}} G1,G2,,GkG_1, G_2,\ldots,G_k, all on the same vertex set VV. Harshith then wonders if there exist kk other graphs H1,H2,,HkH_1, H_2,\ldots,H_k, all on some other vertex set VV' such that:

  • GiG_i is a superb graph of HiH_i for all i{1,2,,k}i\in \{1,2,\ldots,k\}.
  • If a vertex vVv\in V maps to an independent set of size greater than 11 in one Gi,HiG_i, H_i (1ik1\leq i\leq k) pair, then there exists no pair Gj,HjG_j, H_j (1jk,ji1\leq j\leq k, j\neq i) where vv maps to a clique of size greater than 11.

Help Harshith solve his wonder.

^{\text{∗}}For a graph GG, a subset SS of vertices is called an independent set if no two vertices of SS are connected with an edge.

^{\text{†}}For a graph GG, a subset SS of vertices is called a clique if every vertex of SS is connected to every other vertex of SS with an edge.

^{\text{‡}}A graph is a simple undirected graph if its edges are undirected and there are no self-loops or multiple edges between the same pair of vertices.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1001 \le t \le 100). The description of the test cases follows.

The first line of each test case contains two integers nn and kk (1n300,1k101\leq n\leq 300, 1\leq k\leq 10).

Then, there are kk graphs described. The first line of each graph description contains a single integer mm (0mn(n1)20\leq m\leq \frac{n\cdot(n-1)}{2} ).

Next mm lines each contain two space-separated integers uu and vv (1u,vn,uv1\leq u, v\leq n, u\neq v), denoting that an edge connects vertices uu and vv.

It is guaranteed that the sum of mm over all graphs over all test cases does not exceed 21052\cdot 10^5, and the sum of nn over all test cases does not exceed 300300.

Output

For each testcase, print "Yes" if there exists kk graphs satisfying the conditions; otherwise, "No".

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Example
InputCopy
3
5 2
3
3 4
5 3
5 1
6
3 5
3 4
1 4
1 2
2 3
4 2
4 3
0
3
3 1
1 4
1 2
4
4 2
4 3
1 2
2 3
3 2
0
3
3 1
3 2
1 2
OutputCopy
Yes
Yes
No

Note

For the first test case, the following are the graphs of G1,H1G_1, H_1 and G2,H2G_2, H_2 such that G1G_1 is superb graph of H1H_1 and G2G_2 is superb graph of H2H_2.

In each graph, vertex 22 of GiG_i corresonds to independent set {2_1,2_2}\{2\_1, 2\_2\} of corresponding HiH_i and remaining vertices v{1,3,4,5}v\in\{1,3,4,5\} of GiG_i correspond to independent set/clique {v}\{v\} in corresponding HiH_i(a single vertex set can be considered both an independent set and a clique).

In the third test case, it can be proven that the answer is "No".

中文c++回答。

思考

Analyzing block types for graph G

I'm trying to figure out if blow-ups can be independent sets or cliques. For each vertex in G_i, it could correspond to either an independent set or a clique. However, if the block size is 1, it's essentially both. When the block size is greater than 1, it’s specific: either an independent set or a clique. But the adjacency in G_i needs to align with the block type in H_i, considering that G_i doesn’t have self-loops. So, I can define H accordingly.

Defining block assignments for G_i

I need to ensure that for each vertex in V, if it’s assigned an independent set block size > 1 in one graph H_i, it can’t be assigned a clique block size > 1 in any other H_j. The block size assignment for G_i involves choosing whether each vertex has no blow-up, an independent block blow-up, or a clique block blow-up.

The idea is to keep G_i minimal so that its quotient graph is superb. That requires the blocks in each H_i to be the maximal modules. It all boils down to consistent block type assignments across all graphs.

Analyzing blow-up conditions for G_i and H_i

We need to assign block sizes and types for each vertex in G_i, and ensure that if a vertex is a trivial block (size=1), it could be both an independent set and a clique. The main challenge is ensuring that in any graph H_i, a vertex cannot be both in an independent set of size >1 and also be part of a clique block. Looking at the different scenarios, we ultimately determine that if we properly assign block types and sizes, G_i will always be a superb graph of itself.

Examining third test for contradiction

It seems like the conditions allow trivial assignments where each vertex in G_i maps to a block of size 1, satisfying the constraints. However, the third case returns "No," suggesting there's more complexity I'm missing. The key is clarifying whether the vertex set V' for each H_i can be the same as V or if they must strictly differ. If V' and V are disjoint sets, then the trivial solution (G_i = H_i) wouldn’t work. A more intricate mapping might be needed across different graph sets.

Reexamining the third case for consistency

It looks like I misunderstood the problem. The key is that we need a consistent partition across all graphs, and the blocks for each vertex must match across all graphs. Each block in V' must be consistent, and the block types can vary, but the partitioning must cover the entire set V'. The size of each block must be consistent for each vertex in V across all graphs. If a block is larger than size 1, it must be labeled as either "independent" or "clique," and these types must not conflict across graphs. That's where the inconsistency seems to lie.

Thought for 59 seconds

回答

下面的做法基于这样一个观察:

  • “超级图”(superb graph) 的定义决定了它一定是被某图所有“模(module)”——也就是完全同邻(true twins)和完全同非邻(false twins)——合并之后得到的最小商图。
  • 因此,给定的 GiG_i 要能成为某个  ⁣Hi\!H_i 的超级图,它本身必须是“无模”(twin‐free)的:如果 GiG_i 中存在一对不同的顶点 u,vu,v,使得对于除 u,vu,v 之外的任意顶点 ww,都有 (u,wE    v,wE), \bigl(u,w\in E\iff v,w\in E\bigr), 那么 uuvv 在任何可能的 HiH_i 中也会成为模,从而被合并,导致 GiG_i 不可能是最小商图。

另一方面,若所有 GiG_i 都是无模的,那么只要对每个 ii

Hi=Gi, H_i = G_i,

此时每个顶点单独成块(大小 1 的块显然既是团又是独立集),就能保证:

  1. GiG_i 就是 HiH_i 的最小商图。
  2. 因为所有块大小都 = 1,根本不存在“某次是独立集且大小 >1、另一次又是团且大小 >1”这种冲突。

于是问题简化为:检查每个输入图 GiG_i 是否无模。若有任意一个带模(存在“同邻”或“同非邻”)的 GiG_i,答案即为 “No”,否则为 “Yes”。

下面给出基于 C++ 的高效实现,用 bitset 加速模检:

cpp
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int n, k; cin >> n >> k; vector< vector< bitset<300> > > all_bs(k, vector<bitset<300>>(n)); for(int i = 0; i < k; i++){ int m; cin >> m; // 读边并填邻接 for(int e = 0; e < m; e++){ int u, v; cin >> u >> v; --u; --v; all_bs[i][u].set(v); all_bs[i][v].set(u); } } bool ok = true; // 对每个图,检验是否存在一对顶点 u<v 构成 module for(int i = 0; i < k && ok; i++){ auto &bs = all_bs[i]; for(int u = 0; u < n && ok; u++){ for(int v = u+1; v < n; v++){ // 检查 u,v 除彼此外的邻接是否完全一致 // 构造两个 bitset 副本,屏蔽掉对彼此的位 bitset<300> bu = bs[u], bv = bs[v]; bu.reset(v); bv.reset(u); if(bu == bv){ // 找到一对同邻/同非邻 ok = false; break; } } } } cout << (ok ? "Yes\n" : "No\n"); } return 0; }

复杂度分析

  • 每个测试中,总共处理 kk 个图,每个图最多 (n2)\binom{n}{2} 对顶点要比较。
  • 每次比较实际上是对两个 bitset<300>(5~6 个 64 位字)做一次按位异或并全零检查,开销常数非常小。
  • n300, k10n\le300,\ k\le10,总时间足以在几百毫秒内跑完。

分享這個問答