Please explain Sending email more clearly for me please there's a picture of the decription and also please comment on each line if possible on the code below to for me to have a better understanding of what each line is doing. It is in C++. Please also give the space and time complexity and the reason why.   #include #include #include #include #include using namespace std; #define pii pair #define P pair #define F first #define S second #define INF 0x3F3F3F3F3F3F3F3F const int maxn = 20000;   vector G[maxn]; long long dist[maxn];   int main() {     int N, n, m, S, T;     int u, v, w;     cin >> N;     for (int Case=1; Case<=N; Case++){         for (int i=0; i> n >> m >> S >> T;         for (int i=0; i> u >> v >> w;             G[u].push_back({v, w});             G[v].push_back({u, w});         }         // Dijkstra - priority_queue         memset(dist, 0x3F, sizeof(dist));         priority_queue, greater > pq;         dist[S] = 0;         pq.push({0, S});         while (!pq.empty()){             P p = pq.top();             pq.pop();             if (dist[p.S] < p.F) continue;             for (auto nxt: G[p.S]){                 if (dist[nxt.F] > dist[p.S] + nxt.S){                     dist[nxt.F] = dist[p.S] + nxt.S;                     pq.push({dist[nxt.F], nxt.F});                 }             }         }         cout << "Case #" << Case << ": ";         if (dist[T] == INF) cout << "unreachable\n";         else cout << dist[T] << '\n';     }     return 0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please explain Sending email more clearly for me please there's a picture of the decription and also please comment on each line if possible on the code below to for me to have a better understanding of what each line is doing. It is in C++. Please also give the space and time complexity and the reason why.

 

#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
#define pii pair<int, int>
#define P pair<long long, int>
#define F first
#define S second
#define INF 0x3F3F3F3F3F3F3F3F
const int maxn = 20000;
 
vector<pii> G[maxn];
long long dist[maxn];
 
int main() {
    int N, n, m, S, T;
    int u, v, w;
    cin >> N;
    for (int Case=1; Case<=N; Case++){
        for (int i=0; i<maxn; i++) G[i].clear();
        cin >> n >> m >> S >> T;
        for (int i=0; i<m; i++){
            cin >> u >> v >> w;
            G[u].push_back({v, w});
            G[v].push_back({u, w});
        }
        // Dijkstra - priority_queue
        memset(dist, 0x3F, sizeof(dist));
        priority_queue<P, vector<P>, greater<P> > pq;
        dist[S] = 0;
        pq.push({0, S});
        while (!pq.empty()){
            P p = pq.top();
            pq.pop();
            if (dist[p.S] < p.F) continue;
            for (auto nxt: G[p.S]){
                if (dist[nxt.F] > dist[p.S] + nxt.S){
                    dist[nxt.F] = dist[p.S] + nxt.S;
                    pq.push({dist[nxt.F], nxt.F});
                }
            }
        }
        cout << "Case #" << Case << ": ";
        if (dist[T] == INF) cout << "unreachable\n";
        else cout << dist[T] << '\n';
    }
    return 0;
}

Sending email
Description
"A new internet watchdog is creating a stir in
Springfield. Mr. X, if that is his real name, has
come up with a sensational scoop."
Kent Brockman
There are n SMTP servers connected by network cables. Each of the m cables connects two computers and has a certain latency measured in milliseconds required to send an email message. What is th
e shortest time required to send a message from server S to server T along a sequence of cables?
Input
The first line of input gives the number of cases, N. N test cases follow. Each one starts with a line containing n(2 ≤ n ≤ 20000), m(0 ≤m ≤ 50000), S(0 ≤S<n) and T(0 ≤ T <n). $ =
T. The next m lines will each contain 3 integers: 2 different servers (in the range [0, n - 1]) that are connected by a biderectional cable and the latency, w, along with cable ($0 \le w \le 10000).
Output
For each test case, output the line 'Case #x:' followed by the number of milliseconds required to send a message from S to T. Print 'unreachable' if there is no route from S to T.
Sample Input 1 ]
Sample Output 1
3
Case #1: 100
Case #2: 150
2101
Case #3: unreachable
0 1 100
3 3 20
0 1 100
0 2 200
1 2 50
2001
Transcribed Image Text:Sending email Description "A new internet watchdog is creating a stir in Springfield. Mr. X, if that is his real name, has come up with a sensational scoop." Kent Brockman There are n SMTP servers connected by network cables. Each of the m cables connects two computers and has a certain latency measured in milliseconds required to send an email message. What is th e shortest time required to send a message from server S to server T along a sequence of cables? Input The first line of input gives the number of cases, N. N test cases follow. Each one starts with a line containing n(2 ≤ n ≤ 20000), m(0 ≤m ≤ 50000), S(0 ≤S<n) and T(0 ≤ T <n). $ = T. The next m lines will each contain 3 integers: 2 different servers (in the range [0, n - 1]) that are connected by a biderectional cable and the latency, w, along with cable ($0 \le w \le 10000). Output For each test case, output the line 'Case #x:' followed by the number of milliseconds required to send a message from S to T. Print 'unreachable' if there is no route from S to T. Sample Input 1 ] Sample Output 1 3 Case #1: 100 Case #2: 150 2101 Case #3: unreachable 0 1 100 3 3 20 0 1 100 0 2 200 1 2 50 2001
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Concept of Parenthesis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education