GauravPawarR's blog

By GauravPawarR, history, 2 months ago, In English

UVa 1439 — Exclusive Access 2

Tags: Graph Theory, Graph Coloring, DAG, Bitmask DP, Inclusion-Exclusion, Backtracking


Problem Overview

We are given a set of resources and processes, and we need to create a deadlock-free schedule. Each process requires two distinct resources.

A sequence of resource acquisitions forms an alternating wait chain of the form:

$$$ r_1 \to p_1 \to r_2 \to p_2 \to r_3 \to p_3 \dots \to r_N $$$

These chains are transitive: process $$$p_1$$$ and $$$p_2$$$ belong to the same chain if $$$p_1$$$ uses resources $$$r_1$$$ and $$$r_2$$$, while $$$p_2$$$ uses $$$r_2$$$ and $$$r_3$$$.

Initially, the resource graph is undirected: each process represents an undirected edge $$${r_a, r_b}$$$. Directing the edge as either $$$r_a \to r_b$$$ or $$$r_b \to r_a$$$ determines the order in which a process acquires its resources.

The main challenge is to eliminate deadlocks by ensuring that no chain loops back on itself—that is, $$$r_1 \ne r_N$$$.

Among all valid deadlock-free orientations, we want to minimize the length of the maximal alternating wait chain.


Main Idea: Graph Coloring & DAG Construction

How do we eliminate cycles and guarantee $$$r_1 \ne r_N$$$?

We can translate this problem into Graph Coloring.

1. Guaranteeing a DAG

Assign a positive integer color $$$C[u]$$$ to each resource vertex $$$u$$$.

For every directed edge $$$u \to v$$$, we enforce the condition:

$$$ C[u] \lt C[v] $$$

Along any directed path

$$$ r_1 \to r_2 \to \dots \to r_m $$$

the color values must strictly increase:

$$$ C[r_1] \lt C[r_2] \lt \dots \lt C[r_m] $$$

Because a sequence of strictly increasing integers cannot contain repeated values, $$$r_1 = r_N$$$ is mathematically impossible.

This guarantees that the directed resource graph is a Directed Acyclic Graph (DAG), ensuring a deadlock-free schedule.

2. Minimizing Chain Length

By the Gallai-Roy-Vitaver theorem, the minimum number of colors $$$k = \chi(G)$$$ needed to properly color the undirected graph determines the length of the longest path:

$$$ \text{Maximal Path Length (in vertices)} = k $$$
$$$ \text{Maximal Alternating Wait Chain Length} = k - 2 $$$

Thus, the problem reduces to finding the Chromatic Number $$$k = \chi(G)$$$ of a graph with $$$V \le 15$$$ vertices, partitioning $$$V$$$ into $$$k$$$ independent sets, and directing edges from lower-colored vertices to higher-colored vertices ($$$u \to v$$$ if $$$C[u] \lt C[v]$$$).

Now solving this is upto you, share better approaches. Keep practicing!!

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By GauravPawarR, history, 2 months ago, In English

Hey there, fellow programmers. As we all have seen, this year ICPC regionals have been complete disaster and it is really hard to identify who cheated based on plagiarism detectors alone. There was not proper proctoring and in cases even institutionalized cheating. We have literal cheaters doing 10/10 and beating Masters.

What we demand is a fair chance of presenting our skills, nothing else.

ICPC is not just an online contest but a premier contest for actual talent identification and it should not be desecrated and debasement. It is my humble request for support of fellow Indian community in starting petitions for retake with better proctoring, onsite centers as it really pains my heart.

You can give your heart to a craft but if the judges are not fair. You will never win and it causes deep heartache.

It is not about winning but justifying the ache to the heart, the efforts and years behind it.

We started a Google form soon for anonymous misconduct for affected with proofs/strong indication. https://forms.gle/U68UXwuZPhLPmhEQ7

Full text and comments »

  • Vote: I like it
  • +154
  • Vote: I do not like it

By GauravPawarR, history, 2 months ago, In English

So, I have been at it for 2 days and cannot understand, why my code is failing and what can i do better to solve https://www.spoj.com/problems/FACT2/

My code: https://paste.ofcode.org/ZuvTJnRUetnYGfhfScVLpU have been on TLE train for quite sometime and can't figure out what to do.

PS: Please provide resources for such questions, so I can better solve questions.I am a learner

Full text and comments »

  • Vote: I like it
  • +12
  • Vote: I do not like it

By GauravPawarR, history, 21 month(s) ago, In English

So, a newbie here. I have been what you would call not so good at CP. I got introduced to it while I was researching about ICPC. I was new and stupid but ambitious. Joined last year in winter. I was completely new, didn't knew anything. Here I am accelerating with each day progressing. So, in my opinion there's only three things for CP: 1. Observe 2. Learn 3. Practice Just that OBSERVE how these you know RED GUYS solve how the GMs do it, mark them and read their solutions thoroughly till there's none that you can't comprehend. Then, if you come across a thing you cannot comprehend. LOOK FOR IT. There's no other thing, no one's coming to you and tell you. Go around the internet, you are better than AI models in your thinking. Don't give in to AI. LEARN!! YOU ARE A HUMAN, THAT'S HOW WE TOOK OVER THE PLANET. WE LEARNT. and finally, practice religiously and within weeks you will see progress. JUST KEEP AT IT!! MY WISHES TO YOU.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it