Please help me identify the bug in my logic of implementation of pairing of graph section