Cod sursa(job #465876)

Utilizator MihaicorneliuMihai Pojar Mihaicorneliu Data 25 iunie 2010 13:44:15
Problema Mesaj4 Scor 0
Compilator fpc Status done
Runda Stelele Informaticii 2010, gimnaziu si clasa a IX-a, Ziua 1 Marime 0.61 kb
program mesaj4;
type matrice=array[1..100000] of longint;
var a:matrice;
    i,o:text;
    x,m,n,f:longint;
    b:boolean;
begin
  b:=false;
  assign(i,'mesaj4.in');
  reset(i);
  assign(o,'mesaj4.out');
  rewrite(o);
  read(i,n,m);
  if m<n then
    write(o,'-1')
  else
    begin
      for f:=1 to m do
        begin
          read(i,x);
          a[x]:=a[x]+1;
          read(i,x);
          a[x]:=a[x]+1;
        end;
      for f:=1 to m do
        if a[f]=0 then
          b:=true;
      if b then
        write(o,'-1')
      else
        write(o,(n-1)*2)
    end;
  close(o)
end.