A question, water problem, judge all points is not into degrees and out of the same can be.
Question B, test instructions understand is water problem.
Question C. The other party must win at least one of the points after the score mod K. This method can be used to judge.
Problem d, construction problem, not = =.
E, test instructions is the choice of a node each time, the two sons of the same length of the chain to merge into a new chain of the same length. Ask if the end can be a straight chain, if you can output the shortest length. See the code:
1#include <stdio.h>2#include <algorithm>3#include <string.h>4#include <Set>5#include <iostream>6#include <vector>7 using namespacestd;8 Const intN = 2e5 +5;9 Ten intN,root; Onevector<int>G[n]; A intDfsintUintFA) - { - Set<int>S; the for(intI=0; I<g[u].size (); i++) - { - intv =G[u][i]; - if(v = = FA)Continue; + intt =DFS (v,u); - if(t = =-1)return-1; +S.insert (t +1); A } at if(s.size () = =0)return 0; - if(s.size () = =1)return*S.begin (); - if(s.size () = =2&& FA = =-1)return*s.begin () + *S.rbegin (); -Root =u; - return-1; - } in - intMain () to { +CIN >>N; - for(intI=1; i<n;i++) the { * intU,v; scanf"%d%d",&u,&v); $ G[u].push_back (v);Panax Notoginseng g[v].push_back (u); - } the intAns = DFS (1,-1); + if(ans = =-1) ans = DFS (root,-1); A if(ans = =-1)return 0*puts ("-1"); the while(Ans%2==0) Ans >>=1; +printf"%d\n", ans); - return 0; $}
E
Codeforces Round #397 by Kaspersky Lab and Barcelona bootcamp (div. 1 + div. 2 combined)