Cod sursa(job #2052366)
| Utilizator | Data | 30 octombrie 2017 15:22:26 | |
|---|---|---|---|
| Problema | Algoritmul Bellman-Ford | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("fermier.in");
ofstream g("fermier.out");
int v[4002], M, N, P, i, aux, ok, G, x, y;
int main()
{
f>>N>>M>>P;
aux=P;
for (i=1;i<=P;i++)
{
f>>x>>y;
v[i]=(x-1)*M+y;
}
sort (v+1, v+P+1);
v[0]=G;
v[P+1]=1ULL*M*N+1;
for (i=1;i<=P+1;i++)
{
if (v[i]-v[i-1]>1)
if (ok==0)
{
G=v[i]-v[i-1]-1+G;
ok=1;
}
else ok=0;
}
g<<G;
return 0;
}
