elizabeth_zou_fanboi's blog

By elizabeth_zou_fanboi, history, 10 days ago, In English

You are given a directed graph of N nodes. Initially there are M directed edges which are given as input (these are unique and self edges are allowed). You can add a new edge (c, a) if the edges (a,b) and (b,c) exist in the graph. Find the total no of edges in the final graph (when you cannot add any more edges)

NOTE: (a,b) & (b,c) => (c,a) and NOT (a,c)

Constraint: N = 100,000, M = 100,000, TimeLimit = 2s

Full text and comments »

By elizabeth_zou_fanboi, history, 13 days ago, In English

a permutation is valid only if |ai — i| != k for all 1<=i<=n. Count the number of valid permutations.

Constraints: 2 ≤ N ≤ 2000

1 ≤ K ≤ N − 1

EDIT: Thanks for the explanation from methanol.

I implemented that explanation:

cpp code

Full text and comments »