- ID : UVA - 10305 - Ordering Tasks
- Language : Java , C++
- Status : Accepted - Accepted
- Type : Topological Sort.
- Time : 6 Hours.
- Solution :
- Source Removal Method or DFS
- Calculate in Degree.
- Use a queue and insert at first all edges with 0 in Degree those who must be finished first.
- Dequeue every time a node and decrease the in-degree of all it's neighbours as this node is considered to be removed from the queue or the task is done
- each time you decrease the degree of the node. check if this task is available now ( i.e it's degree is zero that means that all of it's dependencies is already finished.
- Problems :
- Check for special cases in the input. the m could be a zero and that what stopped me for 6 hours and I don't know what's wrong with my solution. I discovered that I have to remove the m!=0 condition from the while loop statement.
- I wasn't able to submit the DFS solution don't know what's the reason. but I decided to solve more problems for this period and come to this later
- Code :
This Blog is a Personal record for All The Algorithms Problems I've Solved. It shouldn't be taken as a reference for optimal solutions because I'm just a beginner.
Showing posts with label Graph. Show all posts
Showing posts with label Graph. Show all posts
Friday, March 4, 2011
UVA - 10305 - Ordering Tasks
Tuesday, March 1, 2011
UVA - 10600 - ACM Contest and Blackout
- ID : UVA - 10600 - ACM Contest and Blackout
- Status : Accepted
- Type : Graph MST .
- Time : 2 Hours to Submission.
- Language : Java
- Solution :
- Find MST
- Find MST in every time you remove an edge from the Original MST
- Problems :
- Make sure the MST is not the Original MST by removing the edges from the original MST and looping through all edges.
- Make sure the second minimum MST is larger than the Original MST.
Labels:
10600,
ACM Contest and Blackout,
Graph,
MST,
Second MST,
Uva,
UVA - 10600 - ACM Contest and Blackout
Monday, February 28, 2011
UVA - 11631 - Dark Roads
- ID : UVA - 11631 - Dark Roads
- Status : Accepted
- Type : Graph MST .
- Time : 30 Minutes to Submission.
- Language : Java
- Solution :
- Add Total Costs of Edges.
- Kruskal MST on Edges using Union-Find Algorithm
- Subtract the MST cost from the Total cost.
- Problems :
- Large Data Input so Buffered Reader & Scanner will give TLE
- Don't Use Java Standard Input readers but use this Parser Instead.
Labels:
11631,
Dark Roads,
Graph,
MST,
Uva,
UVA 11631 Dark Roads
UVA - 10307 - Killing Aliens in Borg Maze
- ID : UVA - 10307 - Killing Aliens in Borg Maze
- Status : Accepted
- Type : Graph MST & BFS.
- Time : 5 Hours to Submission.
- Language : Java
- Solution :
- Assume 'S' is a normal node as 'A'
- BFS on all Nodes and Find all Edges.
- Kruskal MST on Edges using Union-Find Algorithm
- Problems :
- hashCode() Function shouldn't be implemented without equals()
- Hashing should be avoided with pre-indexing.
Subscribe to:
Posts (Atom)