0% found this document useful (0 votes)
35 views

Domaci Prog

This document contains code for two algorithms: 1) A recursive function to check connectivity between nodes in a graph represented by a 2D boolean array. It takes the array, a visited array, and two node indexes as parameters. 2) A struct to represent cave regions and a recursive function to find the minimum height needed to connect all caves. It takes a cave index, current height, and a list of neighboring cave regions as parameters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Domaci Prog

This document contains code for two algorithms: 1) A recursive function to check connectivity between nodes in a graph represented by a 2D boolean array. It takes the array, a visited array, and two node indexes as parameters. 2) A struct to represent cave regions and a recursive function to find the minimum height needed to connect all caves. It takes a cave index, current height, and a list of neighboring cave regions as parameters.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Domaci

1. Dostizni cvorovi

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public static bool funkcija(bool[,] veze, bool[] niz, int a, int b)
{
if (a == b)
{
return true;
}
niz[a] = true;
for (int i = 0; i < veze.GetLength(1); i++)
{
if (veze[a, i] && !niz[i])
{
if (funkcija(veze, niz, i, b))
{
return true;
}
}
}
return false;
}
static void Main(string[] args)
{
Console.WriteLine("Unesi broj rutera:");
int n = int.Parse(Console.ReadLine());
bool[,] veze = new bool[n, n];
Console.WriteLine("Unesi broj veza izmedju rutera:");
int m = int.Parse(Console.ReadLine());
Console.WriteLine("Unesi parove rutera koji su povezani:");
for (int i = 0; i < m; i++)
{
string[] s = Console.ReadLine().Split();
int x = int.Parse(s[0]) - 1;
int y = int.Parse(s[1]) - 1;
veze[x, y] = true;
veze[y, x] = true;
}
Console.WriteLine("Unesi broj parova rutera ciju povezanost treba
ispitati:");
int p = int.Parse(Console.ReadLine());
Console.WriteLine("Unesi dva razlicita broja:");
for (int i = 0; i < p; i++)
{
string[] s = Console.ReadLine().Split();
int a = int.Parse(s[0]) - 1;
int b = int.Parse(s[1]) - 1;
bool[] niz = new bool[n];
bool kraj = funkcija(veze, niz, a, b);
Console.WriteLine(kraj ? "da" : "ne");
}
Console.ReadKey();
}
}
}

2. Pecine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication7
{
class Program
{
struct oblast
{
public int x;
public int raz;
public oblast(int x, int raz)
{
this.x = x;
this.raz = raz;
}
}
static int MIN(int x, int h, List<oblast>[] oblasti)
{
int min = h;
foreach (oblast a in oblasti[x])
{
int v = MIN(a.x, h + a.raz, oblasti);
if (v < min)
{
min = v;
}
}
return min;
}
static void Main(string[] args)
{
Console.WriteLine("Unesi visinu tla:");
int h = int.Parse(Console.ReadLine());
Console.WriteLine("Unesi n:");
int n = int.Parse(Console.ReadLine());
List<oblast>[] oblasti = new List<oblast>[n];
for (int i = 0; i < n; i++)
{
oblasti[i] = new List<oblast>();
}
Console.WriteLine("Unesi redni broj polazne dvorane(1), redni broj dolazne
dvorane(2) i visinsku razliku izmedju polazne i dolazne(3), brojevi trebaju biti
razdvojeni razmakom:");
for (int i = 0; i < n - 1; i++)
{
string[] s = Console.ReadLine().Split();
int x = int.Parse(s[0]);
int y = int.Parse(s[1]);
int raz = int.Parse(s[2]);
oblasti[x].Add(new oblast(y, raz));
}
Console.WriteLine("Najmanja nadmorska visina je:");
Console.WriteLine(MIN(0, h, oblasti));
Console.ReadKey();
}
}
}

You might also like