INOI 2020 WA Help

I am trying Subtask 1 of this problem Department Strengths | CodeChef.

This is my code

#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define int long long
#define out(x) cout<<x<<"\n"
#define vout(x,n) f(i,1,n+1)cout<<x[i]<<" "
#define rep(i,n) for(int i(0); i<n; i++)
#define f(i,a,b) for(int i(a); i<b; i++)
#define vi vector<int>
#define pb push_back

const int MAXN = 1e5+10;

vector<vi> adj(MAXN);
vi depth(MAXN, -1);

void dfs(int u){
	for(int v : adj[u]){
			if(depth[v] == -1){
			depth[v] = depth[u] + 1;

int32_t main(){

	int t; cin>>t;

		rep(i,MAXN){depth[i] = -1; adj[i].clear();}

		int n, m, x, y; cin>>n>>m;


		int head;
		if(n&1)head = n;
		else head = 1;

		depth[head] = 1;


		int ans=0; f(i,1,n+1)ans += depth[i];

		if(n&1)cout<<"0 "<<ans<<"\n";
		else cout<<ans<<" 0\n";


	return 0;


It seems my approach is correct but there is some issue with the implementation.
Can someone tell me when the code fails? Solution: 58574643 | CodeChef

Actually, your approach is the problem, not the implementation.

Your code fails on the sample input, so try looking at the explanation of the sample input and the diagram also.


The input consists of multiple departments, each of which is a tree. Your code assumes that there is only one tree when there are actually multiple trees.

Actually I figured it out.

The problem Statement of Subtask 1 is wrong/misleading.

They mean to say there are exactly 2 deparements in Subtask 1, one Odd and one Even.
I assumed there is 1 department in total.

Thanks a lot.