URI ONLINE JUDGE SOLUTION : 1123 - Route Change (INTERMEDIATE PROBLEM) - Life2Coding (2024)

URI ONLINE JUDGE SOLUTION : 1123 – Route Change (INTERMEDIATE PROBLEM)

Problem Summary:

Problem Number: 1123
Problem Name: Route Change
Author’s Name: Maratona de Programação da SBC Brazil
Timelimit: 1
Problem Category: AD-HOC
Problem Source: https://www.urionlinejudge.com.br/judge/en/problems/view/1123

Some Talks about Contest Programming:

An incredible method to enhance your abilities when figuring out how to code is by solving coding problems. Solving different kinds of challenges and riddles can enable you to improve as a problem solver, take in the complexities of a programming dialect, get ready for prospective job interviews, learn new algorithms and more.

An online judge is an online platform to test programs in focused programming challenges. They are likewise used to practice for such challenges. A considerable amount of these platforms also arrange their own programming contests.

10 Steps to Solve Any Problems:

  1. Read the problem completely at least two or three times (or however many makes you feel comfortable)
  2. Identify the subject, the problem belongs to. Is it a sorting or pattern matching problem? Can I use graph theory? Is it related to number theory? etc.
  3. Try to solve the problem manually by considering 3 or 4 sample data sets.
  4. After concentrate on optimizing the manual steps. Try to make it as simple as possible.
  5. Write to write pseudo-code and comments besides the code from the manual steps. One thing you can do is to check after every function is written. Use a good IDE with a debugger, if possible. Don’t need to think much about the syntax. Just focus on the logic and steps.
  6. Replace the comments or pseudo-code with real code. Always check if the values and code are behaving as expected before moving to the new line of pseudo-code.
  7. Then optimize the real code.
  8. Take care of boundary conditions as well.
  9. Get feedback from your teammates, professors, and other developers and also ask your question on Stack Overflow if possible. Try to learn from others’ guidelines and what they are handling those problems. A problem may be solved in several ways. So, don’t get disappointed if you can’t think like an expert. You need to stick to the problem and you will gradually become better and quicker in solving problems like others.
  10. Practice, Practice, and Practice.

N.B: Try to follow the above steps always. If you still can’t get the problem solved, take a look at the solution below. Don’t just copy paste the code. It will kill your creativity. Try to enjoy contest programming and develop your skills.

Solution:

#include <bits/stdc++.h>#define INF 999999using namespace std;typedef pair<int, int> ii;int v[255][255];int caminho[255];int n, m, c, k1;void floydwarshall(){for (int k = c ; k < n ; ++k)for (int i = 0 ; i < n ; ++i)for (int j = 0 ; j < n ; ++j)v[i][j] = min(v[i][j], v[i][k] + v[k][j]);}int main(){int u, w, p;int v1, v2;ios_base :: sync_with_stdio(0); cin.tie(0);while (1){cin >> n >> m >> c >> k1;if (!n) return 0;memset(v, INF, sizeof v);memset(caminho, 0, sizeof caminho);for (int i = 0 ; i < m ; ++i){cin >> u >> w >> p;v[u][w] = v[w][u] = p;}int sum = 0;for (int i = c - 2 ; i >= 0; --i){sum += v[i][i + 1];caminho[i] = sum;}floydwarshall();int ans = v[k1][c - 1];for (int i = 0 ; i < c - 1; ++i){ans = min(v[k1][i] + caminho[i], ans);}cout << ans << 'n';}}

N.B.: Code is Collected from Different Sources

  • Author
  • Recent Posts

Life2Coding

Technology Related Blog at Life2Coding

Feel free to contact us for your any kind of technical problems. We are here to help you.

Latest posts by Life2Coding (see all)

  • How to Create a RGB Color Picker for Images using OpenCV Python - 22 April, 2022
  • Combine Several Images Vertically with Padding using OpenCV Python - 21 April, 2022
  • Combine Several Images Horizontally with Padding using OpenCV Python - 21 April, 2022

Related Posts:

  • Working with Trackbar in OpenCV
  • OpenCV Based Color Replacement GUI Software using PyQT5 and…
  • How to Draw or Write Different Style Texts on OpenCV Images

c++ programming, Contest Programming, problem solving, URI all problem solution list, URI code in C, URI contest programming algorithms, URI OJ problems solution, URI OJ Solution list, URI online judge codes, URI Online Judge Solution, uri online solution, URI Problems Solution, URI Solution in C, URI solver, UVA code in C++, UVA OJ problems solution, UVA online judge codes, UVA solution, UVA solution in C

URI ONLINE JUDGE SOLUTION : 1123 - Route Change (INTERMEDIATE PROBLEM) - Life2Coding (2024)
Top Articles
Latest Posts
Article information

Author: Catherine Tremblay

Last Updated:

Views: 5973

Rating: 4.7 / 5 (47 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Catherine Tremblay

Birthday: 1999-09-23

Address: Suite 461 73643 Sherril Loaf, Dickinsonland, AZ 47941-2379

Phone: +2678139151039

Job: International Administration Supervisor

Hobby: Dowsing, Snowboarding, Rowing, Beekeeping, Calligraphy, Shooting, Air sports

Introduction: My name is Catherine Tremblay, I am a precious, perfect, tasty, enthusiastic, inexpensive, vast, kind person who loves writing and wants to share my knowledge and understanding with you.