CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Challenge 2013
    • May Cook-Off 2013
    • May Challenge 2013
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • Campus Chapters
    • Host your Contest
    • Go for Gold
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
    • Top Contributors on Discuss
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » April Challenge 2012 » Similar Graphs

Similar Graphs

Problem code: SIMGRAPH

  • All Submissions

All submissions for this problem are available.

Chef recently developed an affinity for undirected graphs. He likes pairs of graphs that are similar in structure. However, Chef discovered that when the vertices of a graph are reorganized, it's often the case that the resulting graph, although still structurally similar to the original, can look completely different. Chef wants you to help him find similarities in pairs of graphs.

Chef only considers pairs of graphs where each graph has the same number of vertices (say N). Chef then labels each vertex of each graph with an integer between 1 and N (inclusive), using each integer exactly once per graph. Chef then defines the similarity of the graphs as 2*COMMON/TOTAL, where COMMON is the number of edges appearing in both graphs (that is, the number of unordered pairs {A, B} such that in both graphs there exists an edge between the vertex labelled A and the vertex labelled B), and TOTAL is the total number of edges in both graphs.

Chef's measure of similarity depends on how the vertices are labelled. Chef wants you to help him find a labelling that maximizes the similarity. Optimal solutions are not required, but better solutions will earn more points.

Input

Input will begin with an integer T, the number of test cases. Each test case will begin with an integer N, the number of vertices in both graphs. 2*N lines follow. The first N lines describe the first graph, and the next N lines the second graph. Each graph description consists of N lines of N integers each. The i-th integer on the j-th line will be 1 if there is an edge between vertices i and j, and 0 otherwise. The i-th integer on the j-th line will always be equal to the j-th integer on the i-th line, and the i-th integer on the i-th line will always be 0.

Output

For each test case, output 2 lines with N integers each. Each line must contain a permutation of the integers 1 through N, and indicates how Chef should label the corresponding graph.

Scoring

Your score for each test case is the similarity of the 2 graphs using the labelling you provide. Your overall score is the average of your scores on the individual test cases.

Sample Input

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

Sample Output

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

This 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. Note that better scores are possible.

Test case generation

For each official test file, T is 5. For each test case, N is randomly chosen between 30 and 75. A real number D is randomly chosen between 0.05 and 0.5. For each pair of vertices, an edge is added with probability D. This graph is output as the first graph. An integer C is randomly chosen between 0 and N*(N-1)/2. C distinct pairs of vertices are chosen. For each pair, if an edge currently exists between them, the edge is removed with probability (1-D). If no edge exists between them, one is added with probability D. Then, a random permutation is applied to the vertices of the graph, and it is output as the second graph. You may safely assume there will be no test cases where TOTAL is 0.


Author: pieguy
Tester: laycurse
Editorial http://discuss.codechef.com/problems/SIMGRAPH
Date Added: 11-03-2012
Time Limit: 4 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

How is the N large?

chowshchn @ 1 Apr 2012 10:18 PM
How is the N large?

@chowshchn Please see Test

hiroto_adm @ 2 Apr 2012 05:24 AM
@chowshchn Please see Test case generation. It says N is randomly chosen between 30 and 75.

@admin there must be more

dawnavd @ 4 Apr 2012 11:54 AM
@admin there must be more than one correct output is present then how to decide ??

@all Please explain second

sehrawat.parshant @ 4 Apr 2012 02:55 PM
@all Please explain second test case

please explain the first line

kapilagarwal @ 4 Apr 2012 04:17 PM
please explain the first line of output, won't it always be 1 2 3 4 .... N ?

@can anybody will explain the

khadarbasha @ 4 Apr 2012 04:25 PM
@can anybody will explain the 2nd test case?

@admin....i cannot understand

arulmurugan @ 5 Apr 2012 08:03 AM
@admin....i cannot understand whats done in output...please explain it clearly...

@dawnavg: any valid output

david_adm @ 5 Apr 2012 10:17 AM
@dawnavg: any valid output will do, but better outputs will score more points.

@kapilagarwal: Here's an

david_adm @ 5 Apr 2012 10:24 AM
@kapilagarwal: Here's an explanation of the second test case. The first graph's vertices are labelled 1, 4, 2, 3. The graph has 2 edges: one between the vertices now labelled 1 and 2, and one between the vertices now labelled 2 and 3. The second graph's vertices are labelled 2, 4, 1, 3. This graph also has 2 edges: one between the vertices now labelled 1 and 2, and one between the vertices now labelled 2 and 3.

if we print A{1, 2, 3}, B{1,

abdukodir @ 5 Apr 2012 12:00 PM
if we print A{1, 2, 3}, B{1, 3, 2} for first test case do we earn 2*1/3 points ???

I have a best score of 0.465

phantom11 @ 5 Apr 2012 05:30 PM
I have a best score of 0.465 {http://www.codechef.com/APRIL12/status/SIMGRAPH,phantom11} but still on the rankings page my score is 4.411...Its should have been 4.465...Why is that so??

Is it possible if i keep the

Illusion03 @ 5 Apr 2012 10:08 PM
Is it possible if i keep the labels of graph 1 same in output and changing the labels of graph 2, if doing so gives me similar graphs? Like in the 2nd test case.. if graph 1 is kept as 1 2 3 4 and graph 2 is 3 2 1 4 ? Can it also be the solution for 2nd test case? pls reply.

Hi, I'd like to ask, how is

betlista @ 6 Apr 2012 03:10 AM
Hi, I'd like to ask, how is it possible that some accepted solutions have execution time a lot bigger than allowed time limit - for example 50s ?

it seems that the best

betlista @ 6 Apr 2012 12:52 PM
it seems that the best solutions have running time greater than 10s (actually 11.22s - 77.37s)...

I realized that time limit is

betlista @ 6 Apr 2012 02:17 PM
I realized that time limit is per test case probably so if there are 20 test inputs, limit is 20*4s, right?

@betlista :Nope, the time

phantom11 @ 6 Apr 2012 02:56 PM
@betlista :Nope, the time limit is 4s per test file and a T here is 5.So You have 5 test cases per 4s.There are many such files so the execution time shows the sum total of all those files(and not the average!!).

Is it possible if i keep the

ediston @ 10 Apr 2012 08:52 PM
Is it possible if i keep the labels of graph 1 same in output and changing the labels of graph 2, if doing so gives me similar graphs? Like in the 2nd test case.. if graph 1 is kept as 1 2 3 4 and graph 2 is 3 2 1 4 ? Can it also be the solution for 2nd test case? pls reply.

ediston@ yes. it is possible

abdukodir @ 11 Apr 2012 09:26 AM
ediston@ yes. it is possible

SUCCESSFUL SUBMISSIONS


Fetching successful submissions

CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.