### mahawarvishal10's blog

By mahawarvishal10, history, 5 weeks ago,

Hii!!! I took part in the Atcoder ACL contest 1 held a few days ago. Unfortunately, I am getting wrong answer in the first problem Reachable towns, here is my submission.

All I have done is to sort all cities according to x keeping their city numbers, and connect each city to next city with greater y and x coordinate than it with a bidirectional edge, and finally answer will be the size of connected component of graph for every city. Please tell me if I am incorrect somewhere.

 » 5 weeks ago, # | ← Rev. 3 →   +3 Hmm what does your program get for this case:https://www.imageupload.net/image/E6Vh2If you're only connecting a point with the next one with greater y, then the edge between A and B will be drawn, but I think you'll miss the edge from A to C.EDIT: Yup, that is the issue. On this test case: 3 1 1 2 3 3 2 Your output: 2 2 1Answer: 3 3 3
 » 5 weeks ago, # | ← Rev. 2 →   +3 import java.util.*; import java.io.*; public class Reachable_Towns { static int mod = (int) (1e9 + 7); static List adj[]; public static void main(String[] args) throws java.lang.Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); int a[][]=new int[n][2]; for(int i=0; i(); for(int i=0; ix && a[i][1]>y || a[i][0]