Codeforces Round #368 (Div. 2)

A. Brain's Photos
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.

As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).

Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!

As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.

Photo can be represented as a matrix sized n × m, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:

  • 'C' (cyan)
  • 'M' (magenta)
  • 'Y' (yellow)
  • 'W' (white)
  • 'G' (grey)
  • 'B' (black)

The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively.

Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.

Output

Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.

Examples
input
2 2
C M
Y Y
output
#Color
input
3 2
W W
W W
B B
output
#Black&White
input
1 1
W
output
#Black&White

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char str[205][205];
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        getchar();
        int flag = 0;
        for(int i = 1;i <= n;i++)
        {
            gets(str[i]);
        }
        for(int i = 1;i <= n;i++)
        {
            int len = strlen(str[i]);
            for(int j = 0;j < len;j++)
            {
                if(str[i][j] == 'C' || str[i][j] == 'M'  ||str[i][j] == 'Y')
                {
                    flag = 1;
                    break;
                }
                if(flag)
                    break;
            }
        }
        if(flag)
            printf("#Color\n");
        else
            printf("#Black&White\n");
    }
    return 0;
}

B. Bakery
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.

To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.

Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.

Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).

Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount.

Input

The first line of the input contains three integers nm and k (1 ≤ n, m ≤ 1050 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively.

Then m lines follow. Each of them contains three integers uv and l (1 ≤ u, v ≤ n1 ≤ l ≤ 109u ≠ v) meaning that there is a road between cities u and v of length of l kilometers .

If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input.

Output

Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line.

If the bakery can not be opened (while satisfying conditions) in any of the n cities, print  - 1 in the only line.

Examples
input
5 4 2
1 2 5
1 2 3
2 3 4
1 4 10
1 5
output
3
input
3 1 1
1 2 3
3
output
-1
Note

Image illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened.


错把题意理解成了最短路,直接枚举就行了,汗

学习一下,q巨代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 100005;
const int INF = 0x3f3f3f3f;
vector<pair<int,int> >e[N];
bool vis[N];
int main()
{
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++)
    {
        int u,v,l;
        scanf("%d%d%d",&u,&v,&l);
        e[u].push_back(make_pair(v,l));
        e[v].push_back(make_pair(u,l));
    }
    for(int i=1;i<=k;i++)
    {
        int a;
        scanf("%d",&a);
        vis[a]=1;
    }
    int res=INF;
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])continue;
        for(int j=0;j<(int)e[i].size();j++)
            if(!vis[e[i][j].first])res=min(res,e[i][j].second);
    }
    printf("%d",(res<INF ? res : -1));
    return 0;
}

pair,I get

C. Pythagorean Triples
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are calledPythagorean triples.

For example, triples (3, 4, 5)(5, 12, 13) and (6, 8, 10) are Pythagorean triples.

Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.

Katya had no problems with completing this task. Will you do the same?

Input

The only line of the input contains single integer n (1 ≤ n ≤ 109) — the length of some side of a right triangle.

Output

Print two integers m and k (1 ≤ m, k ≤ 1018), such that nm and k form a Pythagorean triple, in the only line.

In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.

Examples
input
3
output
4 5
input
6
output
8 10
input
1
output
-1
input
17
output
144 145
input
67
output
2244 2245
Note

Illustration for the first sample.



常用套路
简介
所谓勾股数,一般是指能够构成直角三角形三条边的三个正整数(例如a,b,c)。
即a^2+b^2=c^2,a,b,c∈N
又由于,任何一个勾股数组(a,b,c)内的三个数同时乘以一个整数n得到的新数组(na,nb,nc)
仍然是勾股数,所以一般我们想找的是a,b,c互质的勾股数组。
关于这样的数组,比较常用也比较实用的套路有以下两种:[1]
第一套路
当a为大于1的奇数2n+1时,b=2n^2+2n, c=2n^2+2n+1。
实际上就是把a的平方数拆成两个连续自然数,例如:
n=1时(a,b,c)=(3,4,5)
n=2时(a,b,c)=(5,12,13)
n=3时(a,b,c)=(7,24,25)[1]
... ...
这是最经典的一个套路,而且由于两个连续自然数必然互质,所以用这个套路得到的勾股数组全部都是互质的。
第二套路
2、当a为大于4的偶数2n时,b=n^2-1, c=n^2+1
也就是把a的一半的平方分别减1和加1,例如:
n=3时(a,b,c)=(6,8,10)
n=4时(a,b,c)=(8,15,17)
n=5时(a,b,c)=(10,24,26)
n=6时(a,b,c)=(12,35,37)[1]
... ...
这是第二经典的套路,当n为奇数时由于(a,b,c)是三个偶数,所以该勾股数组必然不是互质的;
而n为偶数时由于b、c是两个连续奇数必然互质,所以该勾股数组互质。
所以如果你只想得到互质的数组,这条可以改成,对于a=4n (n>=2), b=4n²-1, c=4n²+1,例如:
n=2时(a,b,c)=(8,15,17)
n=3时(a,b,c)=(12,35,37)
n=4时(a,b,c)=(16,63,65)[1]
... ...(摘自百度百科)

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    long long a,b,c;
    scanf("%lld",&a);
    if(a<=2)
        return 0*printf("-1");
    if(a&1)
    {
        a >>= 1;
        printf("%lld %lld",2*a*a+2*a,2*a*a+2*a+1);
    }
    else
    {
        a >>= 1;
        printf("%lld %lld",a*a-1,a*a+1);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值