Codeforces 27b-tournament (DFS)

Source: Internet
Author: User

Test instructions

There were n teams, and all the teams were going to play it again, and one of them did not give the result of the match.

Ideas

Obviously we can find out which two teams are not given from these pairs.
Then is to determine the outcome of the two teams, DFS to determine whether one of the map to the other can be reached.

Code
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <list>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace STD;#define LL Long Long#define LOWBIT (x) ((x) & ( -X))#define Lson L, Mid, RT << 1#define Rson Mid + 1, R, RT << 1|1#define MP (A, B) Make_pair (A, b)Const intINF =0x3f3f3f3f;Const intMOD =1000000007;Const intMAXN =1e5+Ten;Const DoubleEPS =1e-8;Const DoublePI =ACOs(-1.0);typedefpair<int,int> PII;intnum[ -];intvis[ -];intnum2; vector<int>g[ -];intDfsintu) {Vis[u] =1;if(U = = num2)return 1; for(inti =0; I < g[u].size (); i++) {if(Vis[g[u][i]] = =1)Continue;if(Dfs (G[u][i]))return 1; }return 0;}intMain () {//freopen ("In.txt", "R", stdin);    //freopen ("OUT.txt", "w", stdout);    intN, u, v;Cin>> N; for(inti =0; I < n * (N-1) /2-1; i++) {Cin>> u >> v;        num[u]++, num[v]++;    G[u].push_back (v); }intNUM1 =0; num2 =0; for(inti =1; I <= -; i++)if(Num[i] = = N-2)        {if(!num1) num1 = i;Elsenum2 = i; }if(Dfs (NUM1))printf("%d%d\n", NUM1, num2);Else printf("%d%d\n", num2, NUM1);return 0;}

Codeforces 27b-tournament (DFS)

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.