#P12824. [NERC 2021] Kingdom Partition

    ID: 12604 Type: RemoteJudge 3000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>2021网络流Special JudgeICPCNERC/NEERC

[NERC 2021] Kingdom Partition

题目描述

The King is gone. After the King's rule, all the roads in the Kingdom are run down and need repair. Three of the King's children, Adrian, Beatrice and Cecilia, are dividing the Kingdom between themselves.

Adrian and Beatrice do not like each other and do not plan to maintain any relations between themselves in the future. Cecilia is on good terms with both of them. Moreover, most of the Kingdom's workers support Cecilia, so she has better resources and more opportunity to repair the infrastructure and develop the~economy.

Cecilia proposes to partition the Kingdom into three districts: A (for Adrian), B (for Beatrice), and C (for Cecilia), and let Adrian and Beatrice to negotiate and choose any towns they want to be in their districts, and agree on how they want to partition the Kingdom into three districts.

Adrian's castle is located in town aa, and Beatrice's one is located in town bb. So Adrian and Beatrice want their castles to be located in districts A and B, respectively. Cecilia doesn't have a castle, so district C can consist of no towns.

There is an issue for Adrian and Beatrice. When they choose the towns, they will have to pay for the roads' repair.

The cost to repair the road of length ll is 2l2l gold. However, Adrian and Beatrice don't have to bear all the repair costs. The repair cost for the road of length ll that they bear depends on what towns it connects:

  • For a road between two towns inside district A, Adrian has to pay 2l2l gold;
  • For a road between two towns inside district B, Beatrice has to pay 2l2l gold;
  • For a road between towns from district A and district C, Adrian has to pay ll gold, Cecilia bears the remaining cost;
  • For a road between towns from district B and district C, Beatrice has to pay ll gold, Cecilia bears the remaining cost.

The roads that connect towns from district A and district B won't be repaired, since Adrian and Beatrice are not planning to use them, so no one pays for them. Cecilia herself will repair the roads that connect the towns inside district C, so Adrian and Beatrice won't bear the cost of their repair either.

Adrian and Beatrice want to minimize the total cost they spend on roads' repair. Find the cheapest way for them to partition the Kingdom into three districts.

输入格式

The first line contains two integers nn and mm --- the number of towns and the number of roads in the Kingdom (2n10002 \le n \le 1000; 0m20000 \le m \le 2000).

The second line contains two integers that represent town aa and town bb --- the towns that have to be located in district A and district B, respectively (1a,bn1 \le a, b \le n; aba \ne b).

The following mm lines describe the Kingdom roads. The ii-th of them consists of three integers uiu_i, viv_i, and lil_i representing a road of length lil_i between towns uiu_i and viv_i (1ui,vin1 \le u_i, v_i \le n; uiviu_i \ne v_i; 1li1091 \le l_i \le 10^9).

Each pair of towns is connected with at most one road.

输出格式

In the first line output a single integer --- the minimum total cost of roads' repair for Adrian and Beatrice.

In the second line output a string consisting of nn characters A\tt{A}, B\tt{B}, and C\tt{C}, ii-th of the characters representing the district that the ii-th town should belong to.

If several cheapest ways to partition the Kingdom exist, print any of them.

6 7
1 3
1 2 10
2 3 5
1 3 7
4 5 3
3 6 100
4 6 3
5 6 8
16
ABBCBA

提示

The following picture illustrates the example. Adrian and Beatrice don't pay for the dashed roads, they pay 2l2l for the bold roads, and ll for the solid roads.

So the total cost is 25+3+3=162 \cdot 5 + 3 + 3 = 16.

The castles of Adrian and Beatrice are located in bold towns.