URI Online Judge Solution 1081 DFSr – Depth Hierarchy- Solution in C, C++, Java, Python and C#

URI Online Judge Solution 1081 DFSr – Depth Hierarchy | Beginner
URI Problem Link – https://www.urionlinejudge.com.br/judge/en/problems/view/1081

Problem Name: 1081 DFSr – Depth Hierarchy
Problem Number : URI – 1081 DFSr – Depth Hierarchy
Online Judge : URI Online Judge Solution
Category: Graph
Solution Language : C,C plus plus, java, python, c#(c sharp)

Input Output Sample URI Online Judge Solution 1081:

Input Sample Output Sample
2
12 9
0 1
1 5
5 6
0 4
4 2
2 3
7 8
1 7
10 11
11 8
0 1
1 2
3 4
4 3
5 6
6 8
7 9
9 10
Caso 1:
  0-1 pathR(G,1)
    1-5 pathR(G,5)
      5-6 pathR(G,6)
    1-7 pathR(G,7)
      7-8 pathR(G,8)
  0-4 pathR(G,4)
    4-2 pathR(G,2)
      2-3 pathR(G,3)

  10-11 pathR(G,11)

Caso 2:
  0-1 pathR(G,1)
    1-2 pathR(G,2)

  3-4 pathR(G,4)
    4-3

  5-6 pathR(G,6)
    6-8 pathR(G,8)

  7-9 pathR(G,9)
    9-10 pathR(G,10)

URI Solution 1081 DFSr – Depth Hierarchy Code in C/CPP:

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

#define MAX 20
#define sc(a) scanf("%d", &a);
#define sc2(a, b) scanf("%d%d", &a, &b);

bool disc[MAX];
int graph[MAX][MAX];

void clean(int v) {
int i, j;
for (i = 0; i < v; i++) {
for (j = 0; j < v; j++)
graph[i][j] = 0;
disc[i] = false;
}
}

bool dfs(int v, int n, int s) {
int i;
bool path = false;

disc[v] = true;

for (i = 0; i < n; i++) {
if (graph[v][i] == 1) {
path = true;
if (!disc[i]) {
cout << string(s, ' ');
printf("%d-%d pathR(G,%d)n", v, i, i);
dfs(i, n, s + 2);
} else {
cout << string(s, ' ');
printf("%d-%dn", v, i);
}
}
}

return path;
}

void dfs_runner(int v) {
int i, ind = 0;

while (1) {
if (dfs(ind, v, 2))
puts("");

ind = -1;

for (i = 0; i < v; i++) {
if (!disc[i]) {
ind = i;
break;
}
}

if (ind == -1)
break;
}
}

int main(int argc, char const *argv[]) {
int n, v, e, o, d, c = 1;
sc(n);

while(n--) {
sc2(v, e);
clean(v);

while(e--) {
sc2(o, d);
graph[o][d] = 1;
}

printf("Caso %d:n", c++);
dfs_runner(v);
}

return 0;
}

URI Solution 1081 DFSr – Depth Hierarchy Code / URI 1081 solution in Java:

URI Solution 1081 DFSr – Depth Hierarchy Code / URI 1081 solution in  Python:

URI Solution 1081 DFSr – Depth Hierarchy Code / URI 1081 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 area of a circle code in C, URI 1002 code in C++, URI 1081 DFSr – Depth Hierarchy solution in C, URI solution, URI 1081 DFSr – Depth Hierarchy solution in C,URI 1081 DFSr – Depth Hierarchy solution in C++-CPP,URI 1081 DFSr – Depth Hierarchy solution in C# (C sharp),URI 1081 DFSr – Depth Hierarchy solution in Java,URI 1081 DFSr – Depth Hierarchy solution in Python,

By Maniruzzaman Akash

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

Leave a Reply

Your email address will not be published. Required fields are marked *