[ACM] 2012-Multi-University Training 6th Contest

Could anybody give me some hint to solve this problem?

http://acm.tju.edu.cn/acm/showp3923.html

//