I have been trying to implement the solution to https://oj.uz/problem/view/BOI16_park which is in the DSU category for usaco.guide. I’ve been doing the solution described in the usaco.guide editorial written here https://usaco.guide/solutions/baltic-16-park
My implementation gets one case on subtask 1 and one case on subtask 3 but ultimately gets 0/100. Here is my code: https://hastebin.com/zusopoyuze.cpp
In my code I assigned the borders n(top), n+1(right), n+2(bottom), and n+3(left). If anybody could tell me what I’m doing wrong or maybe just give me a better way to implement it that would be nice.
Thanks!

As an alternative to creating four extra nodes to represent the borders, you can instead store, for each component, whether it “touches” each of the four borders. I think this makes the implementation easier. Here’s my implementation which follows this approach (note that my implementation is pretty awful…) https://github.com/thecodingwizard/competitive-programming/blob/master/BOI/Baltic%2016-park.cpp

Additionally, I would highly recommend getting full score on the first subtask before trying to attempt the other two

How would you know if the borders are connected? Would you store for each border the component it is in?

Also, how would you recommend prioritizing getting full score on the first subtask? Should I make a different solution all together to solve the first subtask. I did manage to get another test case on subtasks 1 and 3 by

There might be a neater way than with four boolean arrays… I was really lazy and just used those four arrays along with the following (insanely dumb) code: