Codeforces 1255B. Fridge Lockers
本文最后更新于:几秒前
Hanh lives in a shared apartment. There are nn people (including Hanh) living there, each has a private fridge.
nn fridges are secured by several steel chains. Each steel chain connects two different fridges and is protected by a digital lock. The owner of a fridge knows passcodes of all chains connected to it. A fridge can be open only if all chains connected to it are unlocked. For example, if a fridge has no chains connected to it at all, then any of nn people can open it.
For exampe, in the picture there are n=4n=4 people and 55 chains. The first person knows passcodes of two chains: 1−41−4 and 1−21−2**. The fridge** 11 can be open by its owner (the person 11**), also two people** 22 and 44 (acting together) can open it.The weights of these fridges are a1,a2,…,ana1,a2,…,an. To make a steel chain connecting fridges uu and vv, you have to pay au**+av**au+av dollars. Note that the landlord allows you to create multiple chains connecting the same pair of fridges.
Hanh’s apartment landlord asks you to create exactly mm steel chains so that all fridges are private. A fridge is private if and only if, among nn people living in the apartment, only the owner can open it (i.e. no other person acting alone can do it). In other words, the fridge ii is not private if there exists the person jj (i≠ji≠j) that the person jj can open the fridge ii.
For example, in the picture all the fridges are private. On the other hand, if there are n=2n=2 fridges and only one chain (which connects them) then both fridges are not private (both fridges can be open not only by its owner but also by another person).
Of course, the landlord wants to minimize the total cost of all steel chains to fulfill his request. Determine whether there exists any way to make exactly mm chains, and if yes, output any solution that minimizes the total cost.
Input
Each test contains multiple test cases. The first line contains the number of test cases TT (1≤T≤101≤T≤10). Then the descriptions of the test cases follow.
The first line of each test case contains two integers nn, mm (2≤n≤10002≤n≤1000, 1≤m≤n1≤m≤n) — the number of people living in Hanh’s apartment and the number of steel chains that the landlord requires, respectively.
The second line of each test case contains nn integers a1**,a2**,…,ana1,a2,…,an (0≤ai≤1040≤ai≤104) — weights of all fridges.
Output
For each test case:
- If there is no solution, print a single integer −1−1.
- Otherwise, print a single integer cc — the minimum total cost. The ii-th of the next mm lines contains two integers uiui and vivi (1≤ui**,vi≤n1≤ui,vi≤n, ui≠vi**ui≠vi), meaning that the ii-th steel chain connects fridges uiui and vivi. An arbitrary number of chains can be between a pair of fridges.
If there are multiple answers, print any.
xxxxxxxxxx19 12#include<bits/stdc++.h>3using namespace std;4int main(void){5 int a[7];6 for(int i=1;i<=6;i++){7 cin>>a[i];8 }9 int sum=0;10 for(int i=1;i<=3;i++){11 if(a[i]==a[i+3]){12 sum++;13 }14 }15 if(sum>=1)cout<<”YES”;16 else cout<<”NO”;17}18//code by lyriv;19//welcome to lyriv.com;c++
input
1 |
|
output
1 |
|
xxxxxxxxxx50 1# =============================================================================2# UPGIT 配置3# =============================================================================45# 默认上传器678default_uploader = “aliyunoss”910# 上传文件名的格式模板(仅特定上传器适配)11# / 目录分隔符, 作用: 是区分目录12# {year} 年份, 例如: 202213# {month} 月份, 例如: 0214# {day} 天, 例如: 0115# {unix_ts} 时间戳, 例如: 164361762616# {fname} 原始文件名,如 logo (不含后缀名)17# {fname_hash} {fname}的 MD5 散列值18# {ext} 文件后缀名, 例如.png19# 下面的例子生成的文件名预览: 2022/01/upgit_20220131_1643617626.png20# 如果目录不存在将会被程序自动创建212223# 修改为你存储桶里想要保存的路径,例如下:24rename = “/blog/img/typora-img/{year}/{month}/upgit_{year}{month}{day}_{unix_ts}{ext}”2526# —————————————————————————–27# 自定义输出格式28# —————————————————————————–29# {url} 图片文件的网络URL地址303132[output_formats]33”bbcode” = “[img]{url}[/img]”34”html” = ‘‘35”markdown-simple” = “
“3637# —————————————————————————–38# 直链替换规则 RawUrl -[replace]-> Url39# —————————————————————————–4041# =============================================================================42# 以下为各个上传器的配置示例. 用不到的留空即可43# =============================================================================4445[uploaders.aliyunoss]46endpoint = “你的接入点地域,例如:https://oss-cn-shenzhen.aliyuncs.com"47access_key_id = “用于操作OSS读写的子用户id”48access_key_secret = “用于操作OSS读写的子用户密码”49bucket_name = “你的存储桶名”50host = “你的存储桶地址”json
1 |
|