In the Cherries Mesh problem, what logic is to applied?

I wrote this code but i am not sure in which test cases it’s giving wrong ans, is the soln right?

int main(){

ios_base::sync_with_stdio(false) ; cin.tie(nullptr) ;

int t ;

cin>>t ;

while(t–){

int ans= 0;

int n,m,ci,di ;

cin>>n>>m ;

for(int i=0;i<m;i++){

cin>>ci>>di ;

}

int cnt=m ;

int tedge = n-1 ;

cout<<m+(tedge-cnt)*2<<endl ;

}

}