1. 程式人生 > >CF 題目集錦 PART 2 #260 div 1 C

CF 題目集錦 PART 2 #260 div 1 C

Andrew plays a game called "Civilization". Dima helps him.

The game has n cities and m bidirectional roads. The cities are numbered from 1 to n. Between any pair of cities there either is a single (unique) path, or there is no path at all. A path is such a sequence of distinct cities v1, v2, ..., v

k, that there is a road between any contiguous cities vi andvi + 1 (1 ≤ i < k). The length of the described path equals to (k - 1). We assume that two cities lie in the same region if and only if, there is a path connecting these two cities.

During the game events of two types take place:

  1. Andrew asks Dima about the length of the longest path in the region where city x
     lies.
  2. Andrew asks Dima to merge the region where city x lies with the region where city y lies. If the cities lie in the same region, then no merging is needed. Otherwise, you need to merge the regions as follows: choose a city from the first region, a city from the second region and connect them by a road so as to minimize the length of the longest path in the resulting region. If there are multiple ways to do so, you are allowed to choose any of them.

Dima finds it hard to execute Andrew's queries, so he asks you to help him. Help Dima.

相關推薦

CF 題目集錦 PART 2 #260 div 1 C

Andrew plays a game called "Civilization". Dima helps him. The game has n cities and m bidirectional roads. The cities are numbered from 1 to n. Betwe

CF 題目集錦 PART 7 #264 div 2 E

【原題】 E. Caisa and Tree time limit per test 10 seconds memory limit per test 256 megabytes input standard input output standard

CF 題目集錦 PART 5 #266 div 2 E

There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships amon

CF 題目集錦 PART 1 #138 div 1 A

A bracket sequence is a string, containing only characters "(", ")", "[" and "]". A correct bracket sequence is a bracket sequence that can be transfor

Codeforces Round #260 (Div. 1) A.Boredom

今天是下定決心好好練DP的第一天,從1600的DP開始做起。 題目連結:點選開啟原題目。 題意:給一個長度位n的整數序列,每次選擇一個數字刪除,刪除這個數的同時比這個數大1和小1的數全部被刪掉,每次得到的值就是你當前選擇的這個數的價值,問能得到的值的總和最大是多少。 思路:在這個序列裡面

Codeforces Round #499 (Div. 1) C. Border || Codeforces Round #499 (Div. 2) E.Border(數論/貝祖定理)

                Codeforces Round #499 (Div. 1) C. Border                 Codeforces Round #499 (Div. 2) E. Border                      

Codeforces Round #485 (Div. 1) C. AND Graph

set put ref \n 出了 gre ber type namespace C. AND Graph time limit per test 4 seconds memory limit per test 256 megabytes input standar

Codeforces Round #302 (Div. 1) C - Remembering Strings 狀壓dp

stat \n space scan name ont def long long mod C - Remembering Strings 思路:最關鍵的一點是字符的個數比串的個數多。 然後就能狀壓啦。 #include<bits/stdc++.h>

Codeforces Round #146 (Div. 1) C - Cyclical Quest 字尾自動機+最小迴圈節

#include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #defin

Codeforces Round #381 (Div. 1) C. Alyona and towers(線段樹)

Alyona has built n towers by putting small cubes some on the top of others. Each cube has size 1 × 1 × 1. A tower is a non-zero amount

Codeforces Round #157 (Div. 1)C(因數分解+二分+組合數)

#include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int MOD = (int)1e9+7; con

Codeforces Round #373 (Div. 1)C(線段樹維護矩陣,矩陣快速冪)

題目連結 C. Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard

Codeforces Round #268 (Div. 1) C. Hack it!(二分+尺取/構造,好題)

Little X has met the following problem recently.  Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 

Codeforces Round #248 (Div. 1)C(AC自動機+DP)

Tachibana Kanade likes Mapo Tofu very much. One day, the canteen cooked all kinds of tofu to sell, but not all tofu is Mapo Tofu, only those spicy enough

Codeforces Round #259 (Div. 1)C

Twilight Sparkle learnt that the evil Nightmare Moon would return during the upcoming Summer Sun Celebration after one thousand years of imprisonment on

Codeforces Round #248 (Div. 1) C - Tachibana Kanade's Tofu AC自動機

C - Tachibana Kanade's Tofu 思路:把 n 個串丟進AC自動機中,然後dp就好啦。 我的程式碼居然是在CF上跑最快的。。 #include<bits/stdc++.h> #define LL long long #define fi first #defi

AIM Tech Round 4 (Div. 1) C - Upgrading Tree 構造 + 樹的重心

sca def dfs clas 菊花 %d href 發現 enter C - Upgrading Tree 我發現我構造題好弱啊啊啊。 很明顯能想到先找到重心, 然後我們的目標就是把所有點接到重心的兒子上,讓重心的兒子子樹變成菊花圖, 這個先把重心到兒子的邊連到

Codeforces Round #114 (Div. 1) C Wizards and Numbers

swa ble style out 數字 pac 如果 div for 題目鏈接:Wizards and Numbers 題意:有兩個數字a, b,假設 a>b,兩個玩家進行遊戲,有兩種操作:1. 令 a=a-b^k,k為正數,且需要保證操作後 a 仍然非負;2. 令

Codeforces Round #284 (Div. 1) C. Array and Operations 二分圖匹配

operation eps return class unsigned color inf ORC ans 因為只有奇偶之間有操作, 可以看出是二分圖, 然後拆質因子, 二分圖最大匹配求答案就好啦。 #include<bits/stdc++.h> #de

Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) C(二分+KMP)

with == codeforce get sum nbsp http def pan http://codeforces.com/contest/1129/problem/C #include<bits/stdc++.h> #define fi fir