Gxor
SRM 670 · 2015-08-31 · by subscriber
Problem Statement
There is a fixed integer n. All graphs in this problem are undirected unweighted graphs on n vertices. The vertices in each graph are numbered 0 through n-1. Additionally, all graphs are simple, i.e., they do not contain self-loops and multiple edges between the same two vertices.
Given a sequence X of such graphs, the xor of that sequence is again a graph on our n vertices. We will denote this graph XOR(X). For each u and v, vertices u and v are connected by an edge in XOR(X) if and only if the number of graphs in X that contain the edge uv is odd. (In other words, the xor of two graphs is a graph that contains the edge uv if and only if exactly one of those two graphs contains the edge uv. We then extend this definition to a xor of arbitrarily many graphs in exactly the same way that is used to extend the bitwise xor to arbitrarily many integers.)
Given a graph, we can convert it into a string using the following pseudocode:
string(G):
for u = 0 .. n-1:
for v = u+1 .. n-1:
if G contains the edge uv: print 1
else: print 0
You are given a
We want to erase some (possibly none, possibly all) graphs from S. Our goal is to produce a sequence T such that XOR(T) is a connected graph. Return the number of ways in which we can do that. (Two ways are considered distinct if the sets of indices of erased graphs differ.)
Note that all n vertices of the graph XOR(T) have to be in the same connected component - there must not be any isolated vertices.Constraints
- S will contain between 1 and 50 elements, inclusive.
- Each element in S will contain exactly n * (n - 1) / 2 characters.
- n will be between 2 and 9, inclusive.
- Each character in S will be either '0' or '1'.
{"1","1","0"}
Returns: 4
This S contains three 2-vertex graphs. Two of them contain the edge 0-1, one doesn't. In order to have a connected XOR(T) we have to erase exactly one of the first two graphs, and we may or may not erase the last graph.
{"011001"}
Returns: 0
{"111011"}
Returns: 1
{"110","011","101"}
Returns: 6
{"000","001","010"}
Returns: 2
Submissions are judged against all 118 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Gxor with a public method long long countsubs(vector<string> S) · 118 test cases · 2 s / 256 MB per case