日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Tournament CodeForces - 27B(dfs)

發(fā)布時間:2023/12/15 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Tournament CodeForces - 27B(dfs) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

The tournament ?Sleepyhead-2010? in the rapid falling asleep has just finished in Berland. n best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. n·(n?-?1)?/?2 games were played during the tournament, and each participant had a match with each other participant.

The rules of the game are quite simple — the participant who falls asleep first wins. The secretary made a record of each game in the form ?xi yi?, where xi and yi are the numbers of participants. The first number in each pair is a winner (i.e. xi is a winner and yi is a loser). There is no draws.

Recently researches form the ?Institute Of Sleep? have found that every person is characterized by a value pj — the speed of falling asleep. The person who has lower speed wins. Every person has its own value pj, constant during the life.

It is known that all participants of the tournament have distinct speeds of falling asleep. Also it was found that the secretary made records about all the games except one. You are to find the result of the missing game.

Input
The first line contains one integer n (3?≤?n?≤?50) — the number of participants. The following n·(n?-?1)?/?2?-?1 lines contain the results of the games. Each game is described in a single line by two integers xi,?yi (1?≤?xi,?yi?≤?n,?xi?≠?yi), where xi и yi are the numbers of the opponents in this game. It is known that during the tournament each of the n participants played n?-?1 games, one game with each other participant.

Output
Output two integers x and y — the missing record. If there are several solutions, output any of them.

Examples
Input
4
4 2
4 1
2 3
2 1
3 1
Output
4 3
題意:n個人,每兩個人都要比一場,給出的場次比原有場次少一場,輸出那一場的正確順序(贏得在前,輸?shù)脑诤?#xff09;
思路:我們可以找出來那兩場是誰和誰打,然后再圖中判斷聯(lián)通就可以了。
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;const int maxx=5e3+100; struct node{int x;int y;bool operator<(const node &a)const{if(a.x!=x) return x<a.x;else return y<a.y;} }p[maxx]; vector<int> s[maxx]; int vis[maxx]; int n;inline void dfs(int u,int v,int &flag) {vis[u]=1;if(flag) return ;for(int i=0;i<s[u].size();i++){int to=s[u][i];if(to==v){flag=1;return ;}if(!vis[to]) dfs(to,v,flag);} } int main() {scanf("%d",&n);int x,y;int m=n;n=(n-1)*n/2-1;for(int i=1;i<=n;i++){scanf("%d%d",&x,&y);s[x].push_back(y);if(x>y) swap(x,y);p[i].x=x;p[i].y=y;}sort(p+1,p+1+n);int l=1,r=2;for(int i=1;i<=n;i++){if(p[i].x!=l||p[i].y!=r) break;else{if(r==m) {l++;r=l+1;}else r++;}}int flag=0;dfs(l,r,flag);if(flag) cout<<l<<" "<<r<<endl;else cout<<r<<" "<<l<<endl; }

努力加油a啊,(o)/~

總結(jié)

以上是生活随笔為你收集整理的Tournament CodeForces - 27B(dfs)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。