Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Un turist vrea sa calatoreasca din orasul X in orasul Y. Calculati drumul minim
- #include <fstream>
- #include <iostream>
- using namespace std;
- ifstream f("A.in");
- ofstream g("B.out");
- const long val = 99;
- int a[50][50], n, i, j, c, v[50], o, p;
- void init()
- {
- f >> n;
- for(i=1; i<=n; i++)
- for(j=1; j<=n; j++)
- if(i == j)
- a[i][j] = 0;
- else
- a[i][j] = val;
- }
- void citire()
- {
- while(f >> i >> j >> c)
- a[i][j] = c;
- do {
- cout << "Nod plecarea: "; cin >> o;
- cout << "Nod sosire: "; cin >> p;
- } while( o > 0 && o < n && p > 0 && p < n);
- }
- void afis()
- {
- for(i=1; i<=n; i++)
- {
- for(j=1; j<=n; j++)
- {
- g << a[i][j] << " ";
- }
- g << '\n';
- }
- }
- void Roy_Floyd()
- {
- for(int k=1; k<=n; k++)
- for(i=1; i<=n; i++)
- for(j=1; j<=n; j++)
- if(a[i][k] + a[k][j] < a[i][j])
- a[i][j] = a[i][k] + a[k][j];
- }
- int main()
- {
- init();
- citire();
- Roy_Floyd();
- afis();
- cout << "* Distanta minima dintre orasele " << o << " - " << p << " este: " << a[o][p];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement