3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

おもしろそうなのでやってみました。

N, M, Q = map(int, input().split())

relations = [tuple(map(int, input().split()))
         for _ in range(M)
         ]

relations.sort(key=lambda x: x[2], reverse=True)

states = [False] * (N + 1)
for _ in range(Q):
    state, member = (
        lambda op, m: (True if op == "+" else False, int(m))
        )( *input().split() )
    
    states[member] = state
    
    print(
        next(
            (f for a, b, f in relations
             if states[a] != states[b]
             )
            , 0
            )
        )

まず、ふたりの関係性を読み込んで、友好度の大きい順にソートします。
入会状態をログで更新し、片方が入会していてもう片方が入会してない関係性で最初にでてきたものを人気として出力します。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?