URI Online Judge Solution 1152 Dark Roads – Solution in C, C++, Java, Python and C#

URI Online Judge Solution 1152 Dark Roads – Solution in C, C++, Java, Python and C#

URI Online Judge Solution  1152 Dark Roads  | Beginner

Problem Name:  1152 Dark Roads solution
Problem Number : URI –  1152 Dark Roads solution
Online Judge : URI Online Judge Solution
Category: Graph
Solution Language : C,C plus plus, java, python, c#(c sharp)

Sample Input Output URI 1152 problem

 Input Simple Output Simple 7 110 1 70 3 51 2 81 3 91 4 72 4 53 4 153 5 64 5 84 6 95 6 110 0 51

URI Solution  1152 Dark Roads  Code in C++ / URI 1152 in cpp:

``#include <cstdio>#include <cstring>#include <cstdlib>using namespace std;#define sc2(a, b) scanf("%d%d", &a, &b)#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)#define MAX 200000struct Grafo { int x, y, v; };int c;int fat[MAX];Grafo grafo[MAX];int cmp(const void *a, const void *b) {    return (*(struct Grafo *)a).v - (*(struct Grafo *)b).v;}void makeset(int n) {    for (int i = 0; i < n; i++)        fat[i] = i;}int find(int n) {    if(fat[n] != n)        fat[n] = find(fat[n]);    return fat[n];}int unionp(int x, int y, int p) {    int i = find(x), j = find(y);    if(i != j) {        c -= grafo[p].v;        if(i > j) fat[i] = j;        else fat[j] = i;        return 1;    }    return 0;}int main(int argc, char const *argv[]) {    int m, n, i;    while(sc2(m, n) && (m || n)) {        c = 0;        memset(&grafo, 0, sizeof(grafo));        for (i = 0; i < n; i++) {            sc3(grafo[i].x, grafo[i].y, grafo[i].v);            c += grafo[i].v;        }        makeset(m);        qsort(grafo, n, sizeof(grafo[0]), cmp);        for (i = 0; i < n; ++i)            unionp(grafo[i].x, grafo[i].y, i);        printf("%dn", c);    }    return 0;}``

URI Solution  1152 Dark Roads  Code / URI 1152 solution in  C# (C Sharp):

Demonstration:

Just implement this in coding. Since having any problem just put a comment below. Thanks

Tags: URI Online Judge Solution, URI OJ Solution list, URI Problems Solution, URI solver, URI all problem solution list, URI  1152 Dark Roads  code in C, URI  1152 Dark Roads  code in C++, URI  1152 Dark Roads  solution in C, URI solution, URI  1152 Dark Roads  solution in C,URI 1002 solution in C++-CPP,URI  1152 Dark Roads  solution in C# (C sharp),URI  1152 Dark Roads  solution in Java,URI  1152 Dark Roads  solution in Python,

By Maniruzzaman Akash

Maniruzzaman Akash is a freelance web developer with most popular Laravel PHP frameork and Vue JS