Pagini recente » Cod sursa (job #1109655) | Cod sursa (job #2291739) | Cod sursa (job #1398563) | Cod sursa (job #378215) | Cod sursa (job #2872947)
// distante.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <fstream>
#include <queue>
#include <climits>
#define ll long long
using namespace std;
ifstream cin("distante.in");
ofstream cout("distante.out");
struct ut
{
ll hova, hossz;
};
priority_queue<ut>que;
bool operator <(const ut& a, const ut& b)
{
return a.hossz > b.hossz;
}
struct adat
{
bool lat = false;
ll hossz = LLONG_MAX;
vector<pair<ll, ll>>sz;
};
vector<adat>x;
vector<ll>y;
ll n, m, s,a,c,b,t;
int main()
{
cin >> t;
while (t--)
{
cin >> n >> m >> s;
x.resize(n + 1);
y.resize(n + 1);
for (int i = 1; i <= n; ++i)
{
cin >> y[i];
}
for (int i = 1; i <= m; ++i)
{
cin >> a >> b >> c;
x[a].sz.push_back({ b,c });
x[b].sz.push_back({ a,c });
}
que.push({ s,0 });
ut akt;
while (!que.empty())
{
akt = que.top();
while (x[akt.hova].lat && !que.empty())
{
que.pop();
if (!que.empty())akt = que.top();
}
if (que.empty())break;
que.pop();
x[akt.hova].lat = true;
x[akt.hova].hossz = akt.hossz;
for (auto& e : x[akt.hova].sz)
{
if (!x[e.first].lat && x[e.first].hossz > (akt.hossz + e.second))
{
x[e.first].hossz = akt.hossz + e.second;
que.push({ e.first , akt.hossz + e.second });
}
}
}
bool ok = false;
for (int i = 1; i <= n; ++i)
{
if (x[i].hossz != y[i])
{
ok = true;
cout << "NU\n";
break;
}
}
if (!ok)cout << "DA\n";
x.clear();
y.clear();
}
return 0;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file