CodeForces 102A - flody

本文概述了AI音视频处理领域的关键技术,包括视频分割、语义识别、自动驾驶、AR、SLAM等,并探讨了其在实际应用中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


I - Clothes
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap.

Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend.

Input

The first input file line contains integers n and m — the total number of clothing items in the shop and the total number of matching pairs of clothing items ().

Next line contains n integers ai (1 ≤ ai ≤ 106) — the prices of the clothing items in rubles.

Next m lines each contain a pair of space-separated integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi). Each such pair of numbers means that theui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi)are different.

Output

Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes).

Sample Input

Input
3 3
1 2 3
1 2
2 3
3 1
Output
6
Input
3 2
2 3 4
2 3
2 1
Output
-1
Input
4 4
1 1 1 1
1 2
2 3
3 4
4 1
Output
-1

Hint

In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles.

The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1.

In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.



 题目意思:

某人要选3件衣服,条件是:选的3件衣服要能两两搭配(也就是两两节点是有边相连的map[i][j] = map[j][i] = 1)

而每个件衣服有自己的价格(也就是每个节点有自己权值),要求选出这样的衣服,使得总的价格最小,要是没有满足条件的,那就输出-1

分析: 其实酒店hi选出最小的环,可以用flody、、、


代码:

#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

#define INF 1 << 29
int g[150][150];
int price[150];
int n, m;
int ans;
int flody () {
	ans = INF;
	for(int i = 1;i <= n;i ++)
		for(int j = i + 1;j <= n;j ++)
			for(int k = j + 1;k <= n;k ++)
				if(g[i][j] && g[j][k] && g[k][i]) {
					ans = min(ans, price[i] + price[j] + price[k]);	
				}
				return ans;
}
int main(){
	int u, v;
	while (scanf("%d%d",&n, &m) != EOF) {
		memset(g, 0, sizeof(g));
		memset(price, 0, sizeof(price));
		for (int  i = 1; i <= n; i ++)
			scanf("%d", &price[i]);
		for (int i = 0; i < m; i ++) {
			scanf("%d%d", &u, &v);
			g[u][v] = g[v][u] = 1;
		}
		//flody();
		if(flody() == INF) printf("-1\n");
		else printf("%d\n", flody());
	}
	return 0;
}



### Codeforces Problem 976C Solution in Python For solving problem 976C on Codeforces using Python, efficiency becomes a critical factor due to strict time limits aimed at distinguishing between efficient and less efficient solutions[^1]. Given these constraints, it is advisable to focus on optimizing algorithms and choosing appropriate data structures. The provided code snippet offers insight into handling string manipulation problems efficiently by customizing comparison logic for sorting elements based on specific criteria[^2]. However, for addressing problem 976C specifically, which involves determining the winner ('A' or 'B') based on frequency counts within given inputs, one can adapt similar principles of optimization but tailored towards counting occurrences directly as shown below: ```python from collections import Counter def determine_winner(): for _ in range(int(input())): count_map = Counter(input().strip()) result = "A" if count_map['A'] > count_map['B'] else "B" print(result) determine_winner() ``` This approach leverages `Counter` from Python’s built-in `collections` module to quickly tally up instances of 'A' versus 'B'. By iterating over multiple test cases through a loop defined by user input, this method ensures that comparisons are made accurately while maintaining performance standards required under tight computational resources[^3]. To further enhance execution speed when working with Python, consider submitting codes via platforms like PyPy instead of traditional interpreters whenever possible since they offer better runtime efficiencies especially important during competitive programming contests where milliseconds matter significantly.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值