POJ 3895 Cycles of Lanes (dfs), poj3895

Source: Internet
Author: User

POJ 3895 Cycles of Lanes (dfs), poj3895

Description

Each of the M lanes of the Park of Polytechnic University of Bucharest connects two of the N crossroads of the park (labeled from 1 to N ). there is no pair of crossroads connected by more than one lane and it is possible to pass from each crossroad to each other crossroad by a path composed of one or more lanes. A cycle of lanes is simple when passes through each of its crossroads exactly once.
The administration of the University wocould like to put on the lanes pictures of the winners of Regional Collegiate Programming Contest in such way that the pictures of winners from the same university to be on the lanes of same simple cycle. that is why the administration wowould like to assign the longest simple cycles of lanes to most successful universities. the problem is to find the longest cy Cles? Fortunately, it happens that each lane of the park is participating in no more than one simple cycle (see the Figure ).

Input

On the first line of the input file the number T of the test cases will be given. each test case starts with a line with the positive integers N and M, separated by interval (4 <= N <= 4444 ). each of the next M lines of the test case contains the labels of one of the pairs of crossroads connected by a lane.

Output

For each of the test cases, on a single line of the output, print the length of a maximal simple cycle.

Sample Input

1 7 8 3 4 1 4 1 3 7 1 2 7 7 5 5 6 6 2

Sample Output

4

Source

Southeastern European Regional Programming Contest 2009


The question is to find the number of vertices in the largest ring, but there is a headache, that is, how can we quickly know the points connected to this point from dfs to a point? Later, I learned how to open a vector Array and save it. The next step is the code. The details are in the code.

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <vector> using namespace std; # define N 5000 vector <int> q [N]; int vis [N]; int n, m; int ans; void dfs (int a, int pos) {int I; vis [a] = pos; for (I = 0; I <q [a]. size (); I ++) {int x = q [a] [I]; if (! Vis [x]) dfs (x, pos + 1); else if (vis [a]-vis [x] + 1> ans) // For example, ring 1 2 3 4 1, vis [1] = 1, vis [4] = 4. Next time 4 is connected to // 1, but vis [1] has been so the ring size vis [4]-vis [1] + 1 ans = vis [a]-vis [x] + 1 ;}} int main () {int I, t; scanf ("% d", & t); while (t --) {scanf ("% d", & n, & m); memset (vis, 0, sizeof (vis); int x, y; for (I = 1; I <= n; I ++) // remember to clear the last data q [I]. clear (); while (m --) {scanf ("% d", & x, & y); q [x]. push_back (y); // q [x] storage and x edge q [y]. push_back (x); // similarly} ans = 0; for (I = 1; I <= n; I ++) if (! Vis [I]) // because a point will appear once, even if two rings have a common edge, // the dfs (I, 1); // if (ans <= 2) will be wrong if (ans <= 2) if not added, // a ring requires three points, but I am depressed, if there is no ring, // How can vis [x] be marked? (Ans = 0 at this time) Is there data like // a B a (⊙ o ⊙ )... Ans = 0; printf ("% d \ n", ans);} return 0 ;}

Dfs is not very familiar yet, but it has something to worry about. You must make up for dfs in the future.
POJ 1001 1005 1006 Translation

POJ 1001
Exponentiation multiplication calculation
Time Limit: 500 MS Memory Limit: 10000 K Time Limit: 500 ms, Memory Limit: 10000 k
Total Submissions: 80267 Accepted: 19039 Total Submissions: 80267 acceptance: 19039

Description

Problems involving the computation of exact values of very large magnstrap and precision are common. for example, the computation of the national debt is a taxing experience for your computer systems. the computation results for numbers involving a large scale and accuracy are consistent. For example, the computing of national debt is essential for many computer systems.

This problem requires that you write a program to compute the exact value of Rn where R is a real number (0.0 <R <99.999) and n is an integer such that 0 <n <= 25. in this case, you need to compile a program to calculate the exact result of the N power of R. Here, R is a real number (0.0 <R <99.999), and n is a positive integer between 0 and 25.
Input
The input will consist of a set of pairs of values for R and n. the R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9. the input is composed of a combination of R and n. The value of R is in column 1-6 and the value of n is in column 8 and 9.
Output
The output will consist of one line for each line of input giving the exact value of R ^ n. leading zeros shocould be suppressed in the output. insignificant trailing zeros must not be printed. don't print the decimal point if the result is an integer. the output is in a row, and an accurate n power of R is given. The output starting with 0 should be omitted. The meaningless last zero cannot appear. If the output is an integer, the decimal point cannot be output.
Hint prompt
If you don't know how to determine wheather encounted the end of input: If you are not sure whether the input is reached,
S is a string and n is an integer s is a string, n is an integer ......

POJ 1005 I Think I Need a Houseboat I Think I Need a house boat
Description
Fred Mapper is considering purchasing some land in Louisiana to build his h... full text>


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.