lutha's blog

By lutha, history, 17 months ago, In English

LINK- https://lightoj.com/contest/code-samurai-2022-preliminary/arena/problem/2353

i'm not sure if link is accessible, so i'm putting problem here. any help is very welcomed, because for u its tiny but for me its huge

Ajobdesh is so advanced in its transportation system that there is a road built between every pair of her N cities. Unfortunately, not all of them are kept open all the time. The traffic police reign supreme and decides which roads to keep open and which ones to close. Even though the Ajob Road Transportation Corporation (ARTC) built a lot of roads, the citizens still have to suffer traffic jams every day.

Every day, the traffic police select a city, close down all the open roads and open up all the closed roads between that city and every other city.

After observing this pattern while stuck at a traffic light, you have been wondering whether one day it would be possible that every road between every pair of cities gets opened up.

Input-----

The first line of input contains the integer N (2 ≤ N ≤ 1000), the number of cities. The cities are labeled with numbers from 1 to N.

The second line contains the integer M (0 ≤ M < N*(N-1)/2), the number of currently opened roads. Each of the following M lines contains two different numbers, the labels of the cities that are currently connected.

Output-------

Print a line containing YES if it is possible to have open roads betweem all pairs of cities. Print NO otherwise.

Sample------

Input 3 2 1 2 2 3 Output---- NO

Sample Input 4 2 1 3 2 4 Output---- YES

Notes---- Explanation of the 2nd input file: They first chose city 1. It open roads 1-2, 1-4, but closes 1-3. Then they chose city 3. It opens 3-1, 3-2, 3-4. The city already has 2-4 open, thus opening a road between every pairs of cities.

Full text and comments »

  • Vote: I like it
  • -12
  • Vote: I do not like it

By lutha, history, 3 years ago, In English

Limits 1s, 512 MB

You are given a bidirectional graph with N vertices and M edges. All edges are painted into either red or black. Your job is to find a spanning tree with some prime number of red edges.

Input First line contains the number of test cases T(1≤ T ≤10).

For each test case:

First line consists of two integers denoting N(1≤ N ≤100000) and M(0≤ M ≤200000).

Next M lines consist of two integers A, B and C denoting there is a directed road from A to B (1≤ A,B ≤N) with color C(0 for black and 1 for red).The graph may contain self loops and multiple edges between two nodes.

Output For every test case, you need to print “Case T: ” (where T is the test case number) followed by the prime number. If you can not construct such a tree print -1. If you can use multiple prime, print the largest one.

Sample Input Output 3 3 3

1 2 0

2 3 1

1 3 1

5 6

1 2 1

2 3 0

3 4 1

1 5 1

5 4 0

2 4 1

5 4

1 2 1

1 3 1

1 4 1

1 5 1 Case 1: 2

Case 2: 3

Case 3: -1

Test Case 1: You can make a spanning tree by connecting

edge 1-2, 2-3 with 1 red edge edge 1-2, 1-3 with 1 red edge edge 1-2, 2-3 with 2 red edges as 2 is the largest prime that can be used to construct a spanning tree, the answer is 1. Test Case 2: You can make a spanning tree in several ways. I'll describe three of them below.

connect edge 1-2, 2-4, 4-5 ,4-3 with 3 red edges connect edge 1-5, 5-4, 4-2, 2-3 with 2 red edges connect edge 1-5, 1-2, 2-4, 4-3 with 4 red edges as 4 is not a prime and 3 is larger between 2 and 3, the answer is 3. Test Case 3: The only way you can make a spanning tree is using 4 red edges. But 4 is not a prime. Hence the answer is -1.

Full text and comments »

  • Vote: I like it
  • -12
  • Vote: I do not like it

By lutha, history, 6 years ago, In English

here's the question statement-

Alice has N balls arranged in a single line. The balls are either red(R), blue(B), green(G) or white(W). They can be represented a string S. Every character of the string is either R, B, G or W.

In the beginning, also there are no two balls of the same color side by side (except white ball). For example GGWWB is not a valid string because there are two green balls together. But GWWB is a valid string as there are no two balls of same color side by side except white balls.

Alice needs to paint all the white balls in one of the other three colors in a way that there are no two balls of the same color side by side.

How many ways Alice can paint the balls? Print the solution modulo 1000000007 (109 + 7).

Input The first line contains the number of test cases T (1 ≤ T ≤ 1000). In each line of the test cases, there will be a string S of length N (1≤ N ≤ 100000).

Total number of character in the input file will be less than 5*10^6.

Output For each test case, print the case number and the answer to the problem.

Sample Input 2 WWG GWGWB

Output

Case 1: 4 Case 2: 2

Explanation for case 1: The four valid ways to color the balls are RBG, BRG, GRG, GBG.

problem link- https://algo.codemarshal.org/contests/icpc-dhaka-preli-18/problems/H

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By lutha, history, 6 years ago, In English

how can i solve this problem

if anyone can pls explain algo . this will be very helpful to me.

thanks.

Full text and comments »

  • Vote: I like it
  • -17
  • Vote: I do not like it