Cod sursa(job #2834536)

Utilizator razviii237Uzum Razvan razviii237 Data 17 ianuarie 2022 10:43:57
Problema A+B Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.83 kb
#include <iostream>
#include <fstream>
#include <queue>
#include <cstring>

using namespace std;

ifstream f("coach.in");
ofstream g("coach.out");

const int maxn = 105, maxm = 5005, inf = 1e9;

struct xy {
    int x, y;
};
struct xyz {
    int x, y, z;
};

int n, m, t;
int a[maxn];

int d[maxn][maxn];
vector <xyz> muchii;
void floyd(int minc, int maxc) {
    int k, i, j;
    for(i = 1; i <= n; i ++) {
        for(j = 1; j <= n; j ++) {
            if(i == j)
                d[i][j] = 0;
            else
                d[i][j] = inf;
        }
    }
    int x, y, z;
    for(auto u : muchii) {
        x = u.x;
        y = u.y;
        z = u.z;
        d[x][y] = z;
        d[y][x] = z;
    }
    for(k = 1; k <= n; k ++) {
        for(i = 1; i <= n; i ++) {
            for(j = 1; j <= n; j ++) {
                if(a[k] >= minc && a[k] <= maxc && a[i] >= minc && a[i] <= maxc && a[j] >= minc && a[j] <= maxc) {
                    if(d[i][k] + d[k][j] < d[i][j]) {
                        d[i][j] = d[i][k] + d[k][j];
                    }
                }
            }
        }
    }
}

int main()
{
    int i, j, x, y, z;

    f >> n >> m >> t;
    for(i = 1; i <= n; i ++) {
        f >> a[i];
    }
    for(i = 1; i <= m; i ++) {
        f >> x >> y >> z;
        muchii.push_back({x, y, z});
    }

    floyd(20, 55);
    /*
    for(i = 1; i <= n; i ++) {
        for(j = 1; j <= n; j ++) {
            g << d[i][j].x << ' ';
        }
        g << '\n';
    }
    */

    bool ok = false;
    for(i = 1; i <= n && ok == false; i ++) {
        for(j = 1; j <= n && ok == false; j ++) {
            if(d[i][j] == t) {
                g << i << ' ' << j << '\n';
                ok = true;
            }
        }
    }

    f.close();
    g.close();
    return 0;
}