rajesh puppala
 

7.Data Storage

In this problem, you are given a network. Network is built upon n servers connected by bidirectional wires. Two servers can be directly connected by at most one wire. Every two servers are connected with some path in the network. Each wire has a fixed positive cost associated with the transmission.

The distance D(V, W) between two servers V and W is defined as the smallest cost of any path connecting V and W in the network. The cost of transmission to the same server is 0 i.e. D(V, V) = 0 for all V. The cost is same on both sides of the transmission.

Some servers offer more services than others. Therefore each server V is marked with a number r(V), called a rank. At each server, data about nearby servers needs to be stored. However, for a given server, not all servers are interesting to store data about. The data about distant servers with low ranks need not to be stored. More specifically, a server W is interesting for a server V, if for every server U such that D(V, U) = D(V, W), the following condition is satisfied: r(U) = r(W).

Let B(V) denote the set of servers which are interesting for a server V. In this problem, you need to compute the total sum of sizes of all sets B(V), which represents the total data need to be stored in the network.

Instructions to use Open PBT Client:

  1. Specify the work directory path in the 'Work Directory Path' field. The path should correspond to your solution work directory.
  2. Download the Support files by clicking the Get Support Files.
  3. You will find the problem directories containing:
    • problem.h file
    • problem.c file

in your work directory.

  1. Write your solution in .c file

Step 1:

In your Solution File:
Add a method int calulateDataSize(int rank[], int wires[][3], int totalRank, int totalWires).

Step 2:

Pass the following parameter to the method calulateDataSize().

  • int    rank[] : represents the ranks of the severs as mentioned in the problem description.
  • int    wires[][3]: contains wire information (source server, destination server and transmission cost).
  • int    totalRank: represents number of ranks.
  • int    totalWires: represents total number of wires.

Step 3:

Write the appropriate code as mentioned in the problem description by following the below given Constraints.

  1. Your method will take rank as an integer array, wires as a two dimension integer array which contains the information about the wires i.e;(source server, destination server and transmission cost) and the respective number of ranks and wires.
  2. The method will calculate the total number of elements in each and every set ( B(V) ).
  3. In turn the sets can be calculated by the way given in the problem statement.
  4. Read the Constraints carefully.

The prototype of the function is

int calulateDataSize(int rank[], int wires[][3], int totalRank, int totalWires)

  • Where rank[i-1] is rank of ith server (1,2,...N), wires contains wire information (source server, destination server and transmission cost), totalRank will gives you the number of ranks and totalWires will gives you the total number of wires.
  • This function returns the total data storage required or -1 in case of error or invalid input condition.

Constraints

  • Every two servers are connected with some path in the network. Otherwise return -1 for error.
  • Maximum number of servers is 10. Otherwise return -1 for error.
  • The rank of each server has to be in range: 1= rank = 10. Otherwise return -1 for error.
  • Transmission cost has to be more than zero between 2 different servers (Negative costs not allowed). Otherwise return -1 for error.

Example 1

Input


     rank = {2, 3, 1, 1}        and
     wires[0] = {1, 4, 30}    represents ( source server, destination server and transmission cost respectively )    and
     wires[1] = {2 ,3, 20}    and
     wires[2] = {3 ,4, 20}
     totalRank = 4
     totalWires = 3

Output


Function "calulateDataSize" returns 9. 

Explanation because B(1) = {1, 2}, B(2) = {2}, B(3) = {2, 3}, B(4) = {1, 2, 3, 4}.

Example 2

Input


     rank = {2, 3, 2, 1}       and
     wires[0] = {1, 2, 30}   represents ( source server, destination server and transmission cost respectively)    and
     wires[1] = {2, 3, 10}   and
     wires[2] = {3, 4, 10}
     totalRank = 4
     totalWires = 3

Output


Function "calulateDataSize" returns 8. 

Example 3

Input


     rank = {2, 3, 2, 1}       and
     wires[0] = {1, 2, 30}   represents ( source server, destination server and transmission cost respectively)    and
     wires[1] = {2, 3, 10}   
     totalRank = 4
     totalWires = 2

Output


Function "calulateDataSize" returns -1. 

For C solutions

Header File

:

datastorage.h

Function Name

:

int calulateDataSize(int rank[], int wires[][3], int totalRank, int totalWires)

File Name

:

datastorage.c

For C++ solutions

Header File

:

datastorage.h

Class Name

:

DataStorage

Function Name

:

int calulateDataSize(int rank[], int wires[][3], int totalRank, int totalWires)

File Name

:

datastorage.cpp

General Instructions

    *

The file / class names, functions, method signatures, header files to be used are mentioned in the problem statement. Do not use your own names or change the method signatures and fields. You can add any number of additional methods.

    *

Do not forget to mention the file extension, either .c or .cpp as the case maybe.

    *

For C solutions, change the value of "C_OR_CPP" macro in header file to 1 and for C++ solutions change the value to 2.

    *

Incase of iostream.h specify as iostream only.

 

Rajesh
7306947200
pedana
krishna dt

JOKES CORNER:
Some Good "Poor Jokes"...
Here are some really bad pj's...Read on if u like some...


Lion Roaring...
what happens when the lion roars???
...
TOM & JERRY Begins......



Hights of Optimism:r
Soldier: "Sir we are surrounded by enemies on all sides!!!"
Sardar Major" Excellent!!! we can attack in any direction"



Flirt like this
What is the height of Flirting?
Its When your love letter starts with "TO WHOMSOEVER IT MAY CONCERN"
..
BRILLIANT WAYS GIRLS TURN GUYS DOWN!!
HE: I'm a photographer I've been looking for a face like yours!
SHE: I'm a plastic surgeon. I've been looking for a face like yours!!!
HE: May I have the pleasure of this dance?
SHE: No, I'd like to have some pleasure too!!!

the sardar...
Q: Why did the Sardar take a pair binoculars with him to a funeral?
A: It was a distant relative's funeral.

gabbbar...
Gabber: Kitne Aadmi they.
Sambha: Sardar Do,
Gabber: Mujhe ginti nahi aati. Do kitne hotey hain?
Sambha: Sardar Do Ek ke baad aata hai.
Gabber : Aur Do ke pehle?
Sambha: Do ke pehle Ek aata hai.
Gabber: To beech mein kaun aata hai?
Sambha: Beech mein koi nahi aata.
Gabber: To fir Dono ek saath kyon nahi atey?
Sambha: Do Ek ke baad hi aa sakta hai, kyonki Do ek se bada hai.
Gabber: Do ek se bada hai? Kitna bada hai?
Sambha Do ek se Ek bada hai?
Gabber: Agar Do ek se ek bada hai to ek ek se kitna bada hai?
Sambha: Sardar, Maine tumhara namak khaya hai, mujhe goli mar do

ek ladki...
A Lady is standing up on top of the hill and she is going to push her Father down from the hill top.....
SO what is the name of this lady ???
... Well her Name is PUSH-PA!!!!!!!!!!

HE: How did you get to be so beautiful?
SHE: I must have been given your share!!!
HE: Will you come out with me this Saturday?
SHE: Sorry! I'm having a headache this weekend!!!
HE: Go on, don't be shy. Ask me out!
SHE: Okay, get out!!!
HE: I think I could make you very happy
SHE: Why? Are you leaving?
HE: What would you say if I asked u to marry me?
SHE: Nothing. I can't talk and laugh at the same time!!!
HE: Can I have your name?
SHE: Why, don't you already have one?
HE: Shall we go and see a film?
SHE: I've already seen it!!!
HE: Do you think it was fate that brought us together?
SHE: Nah, it was plain bad luck!!!
Today, there have been 1 visitors (8 hits) on this page!
This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free