Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 647433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:43:18+00:00 2026-05-13T21:43:18+00:00

I’m training code problems like UvA and I have this one in which I

  • 0

I’m training code problems like UvA and I have this one in which I have to, given a set of n exams and k students enrolled in the exams, find whether it is possible to schedule all exams in two time slots.

Input
Several test cases. Each one starts with a line containing 1 < n < 200 of different examinations to be scheduled.
The 2nd line has the number of cases k in which there exist at least 1 student enrolled in 2 examinations. Then, k lines will follow, each containing 2 numbers that specify the pair of examinations for each case above.
(An input with n = 0 will means end of the input and is not to be processed).

Output:
You have to decide whether the examination plan is possible or not for 2 time slots.

Example:

Input:

3
3
0 1
1 2
2 0
9
8
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0

Ouput:

NOT POSSIBLE.
POSSIBLE.

I think the general approach is graph colouring, but I’m really a newb and I may confess that I had some trouble understanding the problem.
Anyway, I’m trying to do it and then submit it.
Could someone please help me doing some code for this problem?
I will have to handle and understand this algo now in order to use it later, over and over.

I prefer C or C++, but if you want, Java is fine to me 😉

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:43:19+00:00Added an answer on May 13, 2026 at 9:43 pm

    I’ve translated the polygenelubricant’s pseudocode to JAVA code, in order to provide a solution for my problem. We have a submission platform (like uva/ACM contests), so I know it passed even in the problem with more and hardest cases.

    Here it is:

    import java.util.ArrayList;
    import java.util.Hashtable;
    import java.util.Scanner;
    
    /**
     *
     * @author newba
     */
    public class GraphProblem {
    
        class Edge {
            int v1;
            int v2;
    
            public Edge(int v1, int v2) {
                this.v1 = v1;
                this.v2 = v2;
            }
        }
    
        public GraphProblem () {
            Scanner cin = new Scanner(System.in);
    
            while (cin.hasNext()) {
    
                int num_exams = cin.nextInt();
                if (num_exams == 0)
                    break;
                int k = cin.nextInt();
                Hashtable<Integer,String> exams = new Hashtable<Integer, String>();
                ArrayList<Edge> edges = new ArrayList<Edge>();
                for (int i = 0; i < k; i++) {
                    int v1 = cin.nextInt();
                    int v2 = cin.nextInt();
                    exams.put(v1,"UNKNOWN");
                    exams.put(v2,"UNKNOWN");
                    //add the edge from A->B and B->A
                    edges.add(new Edge(v1, v2));
                    edges.add(new Edge(v2, v1));
                }
    
                boolean possible = true;
                for (Integer key: exams.keySet()){
                    if (exams.get(key).equals("UNKNOWN")){
                        if (!colorify(edges, exams,key, "BLACK", "WHITE")){
                            possible = false;
                            break;
                        }
                    }
                }
    
                if (possible)
                    System.out.println("POSSIBLE.");
                else
                    System.out.println("NOT POSSIBLE.");
    
            }
        }
    
        public boolean colorify (ArrayList<Edge> edges,Hashtable<Integer,String> verticesHash,Integer node, String color1, String color2){
    
            verticesHash.put(node,color1);
            for (Edge edge : edges){
                if (edge.v1 == (int) node) {
                    if (verticesHash.get(edge.v2).equals(color1)){
                        return false;
                    }
                    if (verticesHash.get(edge.v2).equals("UNKNOWN")){
                        colorify(edges, verticesHash, edge.v2, color2, color1);
                    }
                }
            }
            return true;
        }
    
        public static void main(String[] args) {
            new GraphProblem();
        }
    }
    

    I didn’t optimized yet, I don’t have the time right new, but if you want, you/we can discuss it here.

    Hope you enjoy it! 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 411k
  • Answers 411k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I love LINQ to SQL; it's easy to work with… May 15, 2026 at 7:54 am
  • Editorial Team
    Editorial Team added an answer You could use a UIScrollView with pagingEnabled = YES for… May 15, 2026 at 7:54 am
  • Editorial Team
    Editorial Team added an answer I ended up solving this with a minor hack: At… May 15, 2026 at 7:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.