Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
An intranet has n computers numbered 1 through n and m one-way communication links between several servers. A path of the form u, v, t represents the time it takes to transfer a file from server u to server v as t. When a computer receives a file from a given computer, it transfers that file to all the other computers it can transfer. One computer can receive messages and transmit messages simultaneously to many other computers. At time 0, computer k wants to transfer a file to all the computers on the network. Ask how long all computers received this file.

input

The keyboard head consists of m + 1 line. The first line contains 3 integers n, m, k (n≤1000, m≤10000). The following M lines, each containing 3 integers u, v, t separated by a space, show that we can transfer files from machine u to machine v in time.

output

In the timing display for all computers that are receiving media from server k

6 6 1
1 2 7
1 3 5
3 5 2
1 5 9
2 4 7
2 6 3

Result
14


What I have tried:

C++
#include <iostream>
using namespace std;
#define TRUE 1 
#define FALSE  0 
#define MAX  10000 
int a[100][100];
int n;
int m;
int sc;
int w;
int chuaxet[100];
int cck[100][3];
void nhap(void) {
    int i, j, k, b;
    cin >> n >> m >> b;
 
    for (i = 1; i <= n; i++) {
        chuaxet[i] = TRUE;//Gán nhãn cho các đỉnh.
        for (j = 1; j <= n; j++)
            a[i][j] = MAX;
    }

  
    for (int p = 1; p <= m; p++) {
        cin >> i >> j >> k;
        a[i][j] = k;
        a[j][i] = k;
    }
}
void PRIM(void) {
    int k, top, min, l, t, u;
    int s[100];
    sc = 0; w = 0; u = 1;
    top = 1;
    s[top] = u;
    chuaxet[u] = FALSE;
    while (sc < n - 1) {
        min = MAX;
        for (int i = 1; i <= top; i++) {
            t = s[i];
            for (int j = 1; j <= n; j++) {
                if (chuaxet[j] && min > a[t][j]) {
                    min = a[t][j];
                    k = t;
                    l = j;
                }
            }
        }
        sc++;
        w = w + min;
        cck[sc][1] = k;
        cck[sc][2] = l;
        chuaxet[l] = FALSE;
        top++;
        s[top] = l;*/
    }
}
void Result(void) {
    for (int i = 1; i <= sc; i++)
        cout << cck[i][1] << " " << cck[i][2] << endl;*/
}
void main(void) {
    nhap();
    PRIM();
    Result();
}
Posted
Updated 17-Apr-21 7:28am
v2
Comments
Patrice T 17-Apr-21 3:01am    
What is the question ?
OriginalGriff 17-Apr-21 3:37am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
Rick York 17-Apr-21 18:06pm    
C++ has true and false as keyboards. There is absolutely NO reason to define macros for those. That is ridiculous!

Also - global variables are a bad idea. Giving them single letter names makes them even worse.

What is the significance of the numbers 100 and 3? Hard-coded values like that are also a bad idea. You should make them const integers with descriptive names.

1 solution

Nice try, but it isnt a C++ solution worth its name. You need more structure like with classes, structs and functions. It is used to gain some clean code for beginners. Be aware that your homework will be read by your teacher or tutor and he doesnt may not understand your bizzare code at first.
You also misses ANY user input and output. That is a severe architectural flaw.

You need to learn about Structs in C++. Get clear whether you should use classes or structs. The main difference is that classes have member functions on top of storing only data.

Tip: write small functions and use tests to verify their correctness.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900