UVa 10926-how many Dependencies?

Source: Internet
Author: User

Title: Give you tasks and dependencies on these tasks, and ask for tasks with the longest dependency chain.

Analysis: Search. You can take advantage of Dfs or memory search.

(Because no ring is a tree structure, the solution for each root calculation is the final result and will not be updated).

Description: An array of tokens to be emptied each time.

#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace Std;int maps[101][101];int used[101];int dfs (int s, int n) {if (Used[s]) r Eturn Used[s];int max = 0;for (int i = 1; I <= n; + + i) if (maps[s][i]) max = max (max, DFS (i, n) +1); return used[s] = M AX;} int main () {int n,m,p;while (~scanf ("%d", &n) && N) {memset (maps, 0, sizeof); memset (used, 0, sizeof (used )); for (int i = 1; I <= n; + + i) {scanf ("%d", &m); for (int j = 1;  J <= M; + + j) {scanf ("%d", &p); maps[i][p] = 1;} Maps[0][i] = 1;} DFS (0, n); int space = 1;for (int i = 2; I <= n; + + i) if (Used[space] < used[i]) space = i;printf ("%d\n", Space);}    return 0;}



UVa 10926-how many Dependencies?

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.