Topic Link: Click to open the link
Test instructions
Petition P70
Ideas:
Simple questions, each point divided or not put.
Import Java.io.printwriter;import Java.util.arraylist;import Java.util.scanner;public class Main {int min (int a,int b) { return a>b?b:a;} int max (int a,int b) {return a>b?a:b;} static int N = 1005;static int M = 2005; arraylist<integer>[] G = new Arraylist[n];int N, m;boolean[] vis = new boolean[n];int[][] dp = new Int[n][2];int DFS (int u) {Vis[u] = true;int ans = 0;dp[u][0] = 0; dp[u][1] = m;//0 means do not put for (int i = 0; i < g[u].size (); i++) {int v = g[u].get (i); if (Vis[v]) Continue;dfs (v);DP [u][1] + = min (dp[v][0]+1, dp[v][1]);DP [u][0] + = dp[v][1]+1;} return min (dp[u][0], dp[u][1]);} void Init () {n = cin.nextint (); m = Cin.nextint (); for (int i = 0; i < n; i++) {vis[i] = false; G[i].clear ();} for (int i = 1, u, v; I <= m; i++) {u = cin.nextint (); v = cin.nextint (); G[u].add (v); G[v].add (U);}} void work () {for (int i = 0; i < N; i++) g[i] = new ArrayList (); int T; T = Cin.nextint (), while (t-->0) {init (); int ans = 0;for (int i = 0; i < n; i++) if (vis[i] = = false) ans + = DFS (i); out.pri NTF ("%d%d%d ", ans/m, M-ans%m, ans%m); Out.println ();}} Main () {cin = new Scanner (system.in); out = new PrintWriter (System.out);} public static void Main (string[] args) {main E = new main (); E.work (); Out.close ();} Public Scanner cin;public static printwriter out;}
UVA 10859 placing lampposts tree DP (water