/******************************************************* * Copyright (C) 2015 Haotian Wu * * This file is the solution to the question: * https://www.hackerrank.com/challenges/journey-to-the-moon * * Redistribution and use in source and binary forms are permitted. *******************************************************/ #include #include #include #include #include #include #include #include #include #include using namespace std; // This is a standard Find-Union Set problem. int fa[100001]; int getfather(int x) { if (x == fa[x]) return x; fa[x] = getfather(fa[x]); return fa[x]; } int main() { int n,p; scanf("%d %d",&n,&p); for (int i=0;i c; for (int i=0;i