pascal
Объяснение:
const n = 5; m = 5;
var a: array [1..n, 1..m] of integer;
procedure fillarray(k: integer);
var i, j: integer;
begin
randomize;
for i := 1 to n do
for j := 1 to m do a[i, j] := random(k);
end;
procedure transarray();
var i, j, k: integer;
for j := i+1 to m do
k := a[i, j];
a[i, j] := a[j, i];
a[j, i] := k;
procedure printarray();
for i:=1 to n do
for j:=1 to m do
write(a[i, j]:3);
writeln;
fillarray(10);
printarray();
transarray();
end.
но у меня извиняйте ,как могу
n,m=map(int,input().split())
tree=[]
count_tree=0
for i in range(m):
u,v = map(int,input().split())
not_in_tree = True
for tr in tree:
if u in tr:
if v not in tr:
tr.append(v)
count_tree +=1
not_in_tree=False
break
elif v in tr:
if u not in tr:
tr.append(u)
if not_in_tree:
tree.append([u,v])
count_tree +=2
print(len(tree) + (n-count_tree))
pascal
Объяснение:
const n = 5; m = 5;
var a: array [1..n, 1..m] of integer;
procedure fillarray(k: integer);
var i, j: integer;
begin
randomize;
for i := 1 to n do
for j := 1 to m do a[i, j] := random(k);
end;
procedure transarray();
var i, j, k: integer;
begin
for i := 1 to n do
for j := i+1 to m do
begin
k := a[i, j];
a[i, j] := a[j, i];
a[j, i] := k;
end;
end;
procedure printarray();
var i, j: integer;
begin
for i:=1 to n do
begin
for j:=1 to m do
write(a[i, j]:3);
writeln;
end;
writeln;
end;
begin
fillarray(10);
printarray();
transarray();
printarray();
end.
но у меня извиняйте ,как могу
Объяснение:
n,m=map(int,input().split())
tree=[]
count_tree=0
for i in range(m):
u,v = map(int,input().split())
not_in_tree = True
for tr in tree:
if u in tr:
if v not in tr:
tr.append(v)
count_tree +=1
not_in_tree=False
break
elif v in tr:
if u not in tr:
tr.append(u)
count_tree +=1
not_in_tree=False
break
if not_in_tree:
tree.append([u,v])
count_tree +=2
print(len(tree) + (n-count_tree))