{"problem":{"name":"Card Collector","description":{"content":"There are $N$ cards placed on a grid with $H$ rows and $W$ columns of squares. The $i$\\-th card has an integer $A_i$ written on it, and it is placed on the square at the $R_i$\\-th row from the top and","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"jsc2019_qual_e"},"statements":[{"statement_type":"Markdown","content":"There are $N$ cards placed on a grid with $H$ rows and $W$ columns of squares.\nThe $i$\\-th card has an integer $A_i$ written on it, and it is placed on the square at the $R_i$\\-th row from the top and the $C_i$\\-th column from the left.\nMultiple cards may be placed on the same square.\nYou will first pick up at most one card from each row.\nThen, you will pick up at most one card from each column.\nFind the maximum possible sum of the integers written on the picked cards.\n\n## Constraints\n\n*   All values are integers.\n*   $1 \\leq N \\leq 10^5$\n*   $1 \\leq H, W \\leq 10^5$\n*   $1 \\leq A_i \\leq 10^5$\n*   $1 \\leq R_i \\leq H$\n*   $1 \\leq C_i \\leq W$\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $H$ $W$\n$R_1$ $C_1$ $A_1$\n$R_2$ $C_2$ $A_2$\n$\\vdots$\n$R_N$ $C_N$ $A_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"jsc2019_qual_e","tags":[],"sample_group":[["6 2 2\n2 2 2\n1 1 8\n1 1 5\n1 2 9\n1 2 7\n2 1 4","28\n\nThe sum of the integers written on the picked cards will be $28$, the maximum value possible, if you pick up cards as follows:\n\n*   Pick up the fourth card from the first row.\n*   Pick up the sixth card from the second row.\n*   Pick up the second card from the first column.\n*   Pick up the fifth card from the second column."],["13 5 6\n1 3 35902\n4 6 19698\n4 6 73389\n3 6 3031\n3 1 4771\n1 4 4784\n2 1 36357\n2 1 24830\n5 6 50219\n4 6 22645\n1 2 30739\n1 4 68417\n1 5 78537","430590"],["1 100000 100000\n1 1 1","1"]],"created_at":"2026-03-03 11:01:14"}}