Cod sursa(job #2447125)

Utilizator Iulia25Hosu Iulia Iulia25 Data 12 august 2019 11:32:58
Problema Sate Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <fstream>
#include <queue>

using namespace std;

ifstream fin ("sate.in");
ofstream fout ("sate.out");

int n, m, x, y, a, b, c, marcat[30005];
queue <int> vecin[30005], cost[30005], q;

int main()  {
  fin >> n >> m >> x >> y;
  for (int i = 1; i <= m; ++i)  {
    fin >> a >> b >> c;
    vecin[a].push(b);
    cost[a].push(c);
    vecin[b].push(a);
    cost[b].push(c);
  }
  int nod;
  q.push(x);
  while (!q.empty())  {
    nod = q.front();
    q.pop();
    while (!vecin[nod].empty())  {
      b = vecin[nod].front();
      vecin[nod].pop();
      c = cost[nod].front();
      cost[nod].pop();
      if (marcat[b])
        continue;
      if (b < nod)
        marcat[b] = marcat[nod] - c;
      else marcat[b] = marcat[nod] + c;
      q.push(b);
      if (b == y)  {
        fout << marcat[b];
        return ((sizeof(q) + sizeof(cost) + sizeof(vecin) + sizeof(marcat)) / 1024/1024);
      }
    }
  }
  return 0;
}