[[+content_image]]
H
H
Hello World2019-10-20 19:57:15
Programming
Hello World, 2019-10-20 19:57:15

In what other cases is a graph called directed?

I'm solving a problem and I can't come up with tests for the problem.
The solution is:

N = int(input())
G = [[0]*N for _ in range(N)]
p = 0
for i in range(N):
  G[i] = list(map(int, input().split()))
  p += sum(G[i])
#if p == 0:print("NO"); exit(); # (Ничего не меняется, будь то YES или NO)

for i in range(N):
  for j in range(N):
    if (i == j and G[i][j] == 1):
      print("NO");exit()
    elif (G[i][j] != G[j][i]):
      print("YES");exit()
print("NO")

Those. if a graph has at least one edge that has a direction, then it is a digraph. But it doesn't pass test 13.
And I don't understand if the graph will be directed if the number of vertices <= 1 or the number of edges = 0?
What kind of tests can you come up with?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
G
Griboks, 2019-10-20
@hello-world00

.e. if a graph has at least one edge that has a direction, then it is a digraph.

Everything is correct.
The number of vertices cannot be 0, i.e., if there are 0 vertices, then this is no longer a graph. The number of edges can be any.
Funny you didn't write test #13.
I don't understand adjacency matrices, but perhaps you should move G[i][j]==1 inside the condition:
for i in range(N):
  for j in range(N):
    if (i == j):
      if (G[i][j] == 1):
          print("NO");exit()
    elif (G[i][j] != G[j][i]):
      print("YES");exit()

ps
Naturally, this code is terrible. Do not repeat in production.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question