{"category_name":"challenge","status":"success","problem_code":"SIMGRAPH","problem_name":"Similar Graphs","body":"<span class=\"solution-visible-txt\">All submissions for this problem are available.<\/span><p>\nChef recently developed an affinity for undirected graphs.\nHe likes pairs of graphs that are similar in structure.\nHowever, Chef discovered that when the vertices of a graph are reorganized, it's often the case that the resulting graph,\nalthough still structurally similar to the original, can look completely different.\nChef wants you to help him find similarities in pairs of graphs.\n<\/p>\n<p>\nChef only considers pairs of graphs where each graph has the same number of vertices (say N).\nChef then labels each vertex of each graph with an integer between 1 and N (inclusive),\nusing each integer exactly once per graph.\nChef then defines the similarity of the graphs as 2*COMMON\/TOTAL, where COMMON is the number of\nedges appearing in both graphs \n(that is, the number of unordered pairs {A, B} such that in both graphs there exists an edge between the vertex labelled A\nand the vertex labelled B), and TOTAL is the total number of edges in both graphs.\n<\/p>\n<p>\nChef's measure of similarity depends on how the vertices are labelled.\nChef wants you to help him find a labelling that maximizes the similarity.\nOptimal solutions are not required, but better solutions will earn more points.\n<\/p>\n<h3>Input<\/h3>\n<p>\nInput will begin with an integer T, the number of test cases.\nEach test case will begin with an integer N, the number of vertices in both graphs.\n2*N lines follow. The first N lines describe the first graph, and the next N lines the second graph.\nEach graph description consists of N lines of N integers each.\nThe i-th integer on the j-th line will be 1 if there is an edge between vertices i and j, and 0 otherwise.\nThe i-th integer on the j-th line will always be equal to the j-th integer on the i-th line,\nand the i-th integer on the i-th line will always be 0.\n<\/p>\n<h3>Output<\/h3>\n<p>\nFor each test case, output 2 lines with N integers each.\nEach line must contain a permutation of the integers 1 through N, and indicates how Chef should label the corresponding graph.\n<\/p>\n<h3>Scoring<\/h3>\n<p>\nYour score for each test case is the similarity of the 2 graphs using the labelling you provide.\nYour overall score is the average of your scores on the individual test cases.\n<\/p>\n<h3>Sample Input<\/h3>\n<pre>2\n3\n0 1 0\n1 0 0\n0 0 0\n0 0 1\n0 0 1\n1 1 0\n4\n0 0 1 0\n0 0 0 0\n1 0 0 1\n0 0 1 0\n0 0 1 1\n0 0 0 0\n1 0 0 0\n1 0 0 0\n<\/pre>\n<h3>Sample Output<\/h3>\n<pre>1 2 3\n1 2 3\n1 4 2 3\n2 4 1 3\n\n<\/pre>\n<p>\nThis output would score 2*0\/3 = 0.0 on the first test case, and 2*2\/4 = 1.0 on the second test case, for an overall score of 0.5.\nNote that better scores are possible.\n<\/p>\n<h3>Test case generation<\/h3>\n<p>\nFor each official test file, T is 5.\nFor each test case, N is randomly chosen between 30 and 75.\nA real number D is randomly chosen between 0.05 and 0.5.\nFor each pair of vertices, an edge is added with probability D.\nThis graph is output as the first graph.\nAn integer C is randomly chosen between 0 and N*(N-1)\/2.\nC distinct pairs of vertices are chosen.\nFor each pair, if an edge currently exists between them, the edge is removed with probability (1-D).\nIf no edge exists between them, one is added with probability D.\nThen, a random permutation is applied to the vertices of the graph, and it is output as the second graph.\nYou may safely assume there will be no test cases where TOTAL is 0.\n<\/p>","languages_supported":"C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS","max_timelimit":"0.729412","source_sizelimit":"50000","problem_author":"pieguy","problem_author_html_handle":"<span \n class='rating' \n style='display: inline-block; \n font-size: 10px; \n background: #FF7F00;\n padding: 0 3px; \n line-height: 1.3; \n color: white;\n margin-right: 2px;'>6★<\/span><span>pieguy<\/span>","problem_tester":"laycurse","problem_tester_html_handle":"<span \n class='rating' \n style='display: inline-block; \n font-size: 10px; \n background: #FF7F00;\n padding: 0 3px; \n line-height: 1.3; \n color: white;\n margin-right: 2px;'>6★<\/span><span>laycurse<\/span>","date_added":"11-03-2012","tags":"<a class='problem-tag-small ' href='\/tags\/problems\/april12'>april12<\/a>, <a class='problem-tag-small ' href='\/tags\/problems\/challenge'>challenge<\/a>, <a class='problem-tag-small ' href='\/tags\/problems\/pieguy'>pieguy<\/a>","editorial_url":"http:\/\/discuss.codechef.com\/problems\/SIMGRAPH","time":{"view_start_date":1334137635,"submit_start_date":1334137635,"visible_start_date":1334136600,"end_date":1735669800,"current":1525454424},"user":{"username":""},"todo":false,"problem_status":"unattempted","is_direct_submittable":false}