Codeforces VK Cup Wild Card Round 1 (AB)

Source: Internet
Author: User

Game Link: http://codeforces.com/contest/522


A. RepostsTime limit per test:1 secondmemory limit per test:256 megabytes

One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp ' s joke to their news feed. Some of them reposted the reposts and so on.

these events is given as a sequence of strings "name1< /span>reposted name2 ", Wherename1 is the name of the person who reposted the joke, Andname2 is the name of the whose news feed, the joke was reposted. It is guaranteed this for each string "name1 Reposted name2 "user" name1 " Didn ' t has the joke in he feed yet, and "name2 " already had it in his feeds by the Moment of repost. Polycarp was registered as "polycarp " and initially the joke were only in his feed.< /span>

Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp ' s joke.

Input

The first line of the input contains integer n (1?≤? N? ≤?200)-the number of reposts. Next follow the reposts in the order they were made. Each of the them are written on a, and looks as "name1reposted name2". All the names in the input consist of lowercase or uppercase 中文版 letters and/or digits and has lengths from 2 to C Haracters, inclusive.

We know that the user names be case-insensitive, that's, the names that's only differ Same social network user.

Output

Print a single integer-the maximum length of a repost chain.

Sample Test (s)Input
5tourist reposted Polycarppetr reposted TOURISTWJMZBMR reposted Petrsdya reposted Wjmzbmrvepifanov reposted Sdya
Output
6
Input
6Mike reposted Polycarpmax reposted Polycarpeveryone reposted Polycarp111 reposted Polycarpvkcup reposted Polycarpcodeforces reposted Polycarp
Output
2
Input
1SoMeStRaNgEgUe reposted Polycarp
Output
2


The number of nodes to find the longest chain

Title Analysis: Hash with the map string, then run down the Floyd, code to write the ugly


#include <cstdio> #include <map> #include <string> #include <algorithm> #include <iostream >using namespace Std;map <string, int> mp;map <string, int>:: iterator it;int Const MAX = 505;int g[max][m    AX], Cnt;int Floyd () {int ans = 1;  for (int k = 0, K < cnt; k++) {for (int i = 0; i < cnt, i++) {for (int j = 0; J < CNT; J + +) {if (G[i][k] && g[k][j]) {g[i][j] = G[i][k] + G K                    [j];                ans = max (ans, g[i][j]); }}}} return ans;}    void trans (string a) {int i = 0;        while (A[i]) {if (A[i] >= ' A ' && a[i] <= ' Z ') a[i] + = ' A '-' a ';    i++;    }}int Main () {int n;    CNT = 0;    scanf ("%d", &n);        while (n--) {string A, TMP, B;        CIN >> a >> tmp >> B;        int i = 0; while (A[i]) {if (A[i]>= ' A ' && a[i] <= ' Z ') a[i] + = ' A '-' a ';        i++;        } i = 0;            while (B[i]) {if (B[i] >= ' A ' && b[i] <= ' Z ') b[i] + = ' A '-' a ';            i++;        } Mp[a] = cnt++;        it = Mp.find (a);        if (it = = Mp.end ()) mp[a] = cnt++;        it = Mp.find (b);        if (it = = Mp.end ()) mp[b] = cnt++;    G[MP[A]][MP[B]] = 1;    } int ans = Floyd (); printf ("%d\n", ans + 1);}



B. Photo to RememberTime limit per test:2 secondsmemory limit per test:256 megabytes
One day n friends met at a party, they hadn ' t seen each other for a long time and so they decided to make a group Photo together.

simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels:the i -th of T Hem occupies the rectangle of width w i Pixels and Height h i pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed Fri Ends, Is W ? x? H , where W is the total sum of all widths and < Em>h is the maximum height of all the photographed friends.

As is usually the case, the friends made N photos-the J-th (1?≤? J. ≤? n) photo had everybody except for theJ-th Friend as he is the photographer.

Print the minimum size of each made photo in pixels.

Input

The first line contains integer n (2?≤? N? ≤?200?000)-the number of friends.

Then n lines follow:thei-th line contains information about the i-th friend. The line contains a pair of integers wi,? Hi (1?≤? Wi? ≤?10,?1?≤? Hi? ≤?1000)-the width and height in pixels of the corresponding rectangle.

Output

Print n space-separated numbersb1,? b2,?...,? bn, wherebi -the total number of pixels on the minimum pho To containing all friends expect for theI-th one.

Sample Test (s)Input
31 105 510 1
Output
Input
32 11 22 1
Output


Main topic: To N wi and Hi, to delete the first I wi and hi after the remaining WI and with Hi's maximum value of product

Title Analysis: Direct simulation of the maximum and secondary value, if the maximum value of more than one mark, then there is nothing ...

#include <cstdio> #include <algorithm> #define LL long longusing namespace Std;int const MAX = 2 * 1e6 + 5;ll w[    MAX], H[max];int main () {int n;    ll sum = 0, ma1 = 0, ma2 = 0, pos = 0;    BOOL flag = FALSE;    scanf ("%d", &n);        for (int i = 0; i < n; i++) {scanf ("%i64d%i64d", &w[i], &h[i]);        Sum + = W[i];            if (MA1 < h[i]) {ma1 = H[i];        pos = i;        }} for (int i = 0; i < n; i++) {if (i = = pos) continue;            if (h[i] = = MA1) {flag = true;        Continue    } MA2 = max (MA2, H[i]); } for (int i = 0; i < n; i++) {if (h[i] = = MA1) {if (flag) printf ("%i64d"            , (Sum-w[i]) * ma1);        else printf ("%i64d", (Sum-w[i]) * ma2);    } else printf ("%i64d", (Sum-w[i]) * ma1); } printf ("\ n");}


Codeforces VK Cup Wild Card Round 1 (AB)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.