1166 Summit (25)

A summit (峰會) is a meeting of heads of state or government. Arranging the rest areas for the summit is not a simple job. The ideal arrangement of one area is to invite those heads so that everyone is a direct friend of everyone.

Now given a set of tentative arrangements, your job is to tell the organizers whether or not each area is all set.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers N (≤ 200), the number of heads in the summit, and M, the number of friendship relations. Then M lines follow, each gives a pair of indices of the heads who are friends to each other. The heads are indexed from 1 to N.

Then there is another positive integer K (≤ 100), and K lines of tentative arrangement of rest areas follow, each first gives a positive number L (≤ N), then followed by a sequence of L distinct indices of the heads. All the numbers in a line are separated by a space.

Output Specification:

For each of the K areas, print in a line your advice in the following format:

  • if in this area everyone is a direct friend of everyone, and no friend is missing (that is, no one else is a direct friend of everyone in this area), print Area X is OK..

  • if in this area everyone is a direct friend of everyone, yet there are some other heads who may also be invited without breaking the ideal arrangement, print Area X may invite more people, such as H. where H is the smallest index of the head who may be invited.

  • if in this area the arrangement is not an ideal one, then print Area X needs help. so the host can provide some special service to help the heads get to know each other.

Here X is the index of an area, starting from 1 to K.

Sample Input:

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

Sample Output:

Area 1 is OK.
Area 2 is OK.
Area 3 is OK.
Area 4 is OK.
Area 5 may invite more people, such as 3.
Area 6 needs help.

?題目大意:為峰會安排休息區,一個理想的安排是邀請這些領導人,每個人互相之間都是直接朋友。給定一套暫定的安排,判斷每個區域是否都已準備就緒。抽象一下可以看做有m條邊,n個頂點的無向圖,給定k次查詢,每次查詢給出點集中點的數量,以及頂點編號,問這些點是否兩兩連通,如果不聯通輸出needs help;如果是的話,是否存在其它頂點加入后仍然保持兩兩連通,有這樣的點的話輸出最小的點編號,否則輸出OK。

分析:由于點的數量很少,可以直接用暴力的方法檢查是否是連通子圖,如果是的話再檢查是否有其它點加入后仍然連通。

#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define INF 0xffffffff
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
#define db4(x,y,z,r) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<endl
#define db5(x,y,z,r,w) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<", "<<#w<<"="<<(w)<<endl
using namespace std;int main(void)
{#ifdef testfreopen("in.txt","r",stdin);//freopen("in.txt","w",stdout);clock_t start=clock();#endif //testint n,m;scanf("%d%d",&n,&m);int num[n+5][n+5];for(int i=0;i<=n;++i)for(int j=0;j<=n;++j)num[i][j]=0;for(int i=0;i<m;++i){int a,b;scanf("%d%d",&a,&b);num[a][b]=num[b][a]=1;}int k;scanf("%d",&k);for(int Case=1;Case<=k;++Case){printf("Area %d ",Case);int cnt,f=1;scanf("%d",&cnt);int ques[cnt+5]={0};for(int i=0;i<cnt;++i){scanf("%d",&ques[i]);if(i&&f){for(int j=0;j<i;++j){if(!num[ques[i]][ques[j]]){f=0;break;}}}}if(!f)printf("needs help.\n");else{int index=1;for(int i=1;i<=n;++i){f=1;index=i;for(int j=0;j<cnt;++j){if(num[i][ques[j]]==0){f=0;break;}}if(f)break;}if(!f)printf("is OK.\n");else printf("may invite more people, such as %d.\n",index);}}#ifdef testclockid_t end=clock();double endtime=(double)(end-start)/CLOCKS_PER_SEC;printf("\n\n\n\n\n");cout<<"Total time:"<<endtime<<"s"<<endl;        //s為單位cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms為單位#endif //testreturn 0;
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/66469.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/66469.shtml
英文地址,請注明出處:http://en.pswp.cn/web/66469.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

圖論DFS:黑紅樹

我的個人主頁 {\large \mathsf{{\color{Red} 我的個人主頁} } } 我的個人主頁 往 {\color{Red} {\Huge 往} } 往 期 {\color{Green} {\Huge 期} } 期 文 {\color{Blue} {\Huge 文} } 文 章 {\color{Orange} {\Huge 章}} 章 DFS 算法&#xff1a;記憶化搜索DFS 算法&#xf…

C++,設計模式,【目錄篇】

文章目錄 1. 簡介2. 設計模式的分類2.1 創建型模式&#xff08;Creational Patterns&#xff09;&#xff1a;2.2 結構型模式&#xff08;Structural Patterns&#xff09;&#xff1a;2.3 行為型模式&#xff08;Behavioral Patterns&#xff09;&#xff1a; 3. 使用設計模式…

掌握提示詞工程:大模型使用入門指南

掌握提示詞工程&#xff1a;大模型使用入門指南 近年來&#xff0c;大語言模型&#xff08;如 GPT、Claude 等&#xff09;的強大能力令人印象深刻&#xff0c;但要想充分發揮這些模型的潛力&#xff0c;僅僅依靠其預訓練能力還不夠。提示詞工程&#xff08;Prompt Engineerin…

如何使用 useMemo 和 memo 優化 React 應用性能?

使用 useMemo 和 memo 優化 React 應用性能 在構建復雜的 React 應用時&#xff0c;性能優化是確保應用流暢運行的關鍵。React 提供了多種工具來幫助開發者優化組件的渲染和計算邏輯&#xff0c;其中 useMemo 和 memo 是兩個非常有用的 Hook。本文將詳細介紹這兩個工具的使用方…

Agent Laboratory: Using LLM Agents as Research Assistants 論文簡介

加速機器學習研究的智能實驗室——Agent Laboratory 1. 引言 隨著人工智能技術的飛速發展&#xff0c;機器學習領域正以前所未有的速度推進科學發現和技術創新。然而&#xff0c;傳統的科學研究模式往往受到時間、資源和專業知識限制&#xff0c;阻礙了研究者們探索新想法的能…

【網絡協議】【http】【https】ECDHE-TLS1.2

【網絡協議】【http】【https】ECDHE-TLS1.2 ECDHE算法 1.客戶端和服務器端事先確定好使用哪種橢圓曲線&#xff0c;和曲線上的基點G&#xff0c;這兩個參數都是公開的&#xff0c; 雙方各自隨機生成一個隨機數作為私鑰d&#xff0c;并與基點 G相乘得到公鑰Q(QdG)&#xff0c…

規避路由沖突

路由沖突是指在網絡中存在兩個或多個路由器在進行路由選擇時出現矛盾&#xff0c;導致網絡數據包無法正確傳輸&#xff0c;影響網絡的正常運行。為了規避路由沖突&#xff0c;可以采取以下措施&#xff1a; 一、合理規劃IP地址 分配唯一IP&#xff1a;確保每個設備在網絡中都有…

項目實戰--網頁五子棋(游戲大廳)(3)

我們的游戲大廳界面主要需要包含兩個功能&#xff0c;一是顯示用戶信息&#xff0c;二是匹配游戲按鈕 1. 頁面實現 hall.html <!DOCTYPE html> <html lang"ch"> <head><meta charset"UTF-8"><meta name"viewport"…

大模型UI:Gradio全解11——Chatbot:融合大模型的聊天機器人(4)

大模型UI&#xff1a;Gradio全解11——Chatbot&#xff1a;融合大模型的聊天機器人&#xff08;4&#xff09; 前言本篇摘要11. Chatbot&#xff1a;融合大模型的多模態聊天機器人11.4 使用Blocks創建自定義聊天機器人11.4.1 簡單聊天機器人演示11.4.2 立即響應和流式傳輸11.4.…

【線性代數】行列式的概念

d e t ( A ) ∑ i 1 , i 2 , ? , i n ( ? 1 ) σ ( i 1 , ? , i n ) a 1 , i 1 a 2 , i 2 , ? , a n , i n det(A) \sum_{i_1,i_2,\cdots,i_n } (-1)^{\sigma(i_1,\cdots,i_n)} a_{1,i_1}a_{2,i_2},\cdots, a_{n,i_n} det(A)i1?,i2?,?,in?∑?(?1)σ(i1?,?,in?)a1…

關于php語言api接口開發的流程

確定接口需求&#xff1a;首先明確接口的功能和需求&#xff0c;包括輸入參數、輸出結果以及接口的業務邏輯。 設計接口路由&#xff1a;根據接口需求&#xff0c;設計具體的接口路由&#xff0c;即URL路徑&#xff0c;用于訪問接口。 搭建PHP環境&#xff1a;確保你的服務器上…

STM32 FreeRTOS內存管理簡介

在使用 FreeRTOS 創建任務、隊列、信號量等對象時&#xff0c;通常都有動態創建和靜態創建的方式。動態方式提供了更靈活的內存管理&#xff0c;而靜態方式則更注重內存的靜態分配和控制。 如果是1的&#xff0c;那么標準 C 庫 malloc() 和 free() 函數有時可用于此目的&#…

【Linux系統編程】—— 深度解析進程等待與終止:系統高效運行的關鍵

文章目錄 進程創建再次認識fork()函數fork()函數返回值 寫時拷貝fork常規?法以及調用失敗的原因 進程終?進程終止對應的三種情況進程常?退出?法_exit函數exit函數return退出 進程等待進程等待的必要性進程等待的?法 進程創建 再次認識fork()函數 fork函數初識&#xff1…

國產編輯器EverEdit -重復行

1 重復行 1.1 應用場景 在代碼或文本編輯過程中&#xff0c; 經常需要快速復制當前行&#xff0c;比如&#xff0c;給對象的多個屬性進行賦值。傳統的做法是&#xff1a;選中行-> 復制-> 插入新行-> 粘貼&#xff0c;該操作有4個步驟&#xff0c;非常繁瑣。 那有沒…

基于VSCode+CMake+debootstrap搭建Ubuntu交叉編譯開發環境

基于VSCodeCMakedebootstrap搭建Ubuntu交叉編譯開發環境 1 基于debootstrap搭建目標系統環境1.1 安裝必要軟件包1.2 創建sysroot目錄1.3 運行debootstrap1.4 掛載必要的虛擬文件系統1.5 進入目標系統1.6 使用目標系統&#xff08;以安裝zlog為例&#xff09;1.7 清理和退出 2 基…

NiceFish(美人魚)

前端有 3 個版本&#xff1a; 瀏覽器環境移動端環境Electron 環境 服務端有 2 個版本&#xff1a; SpringBoot 版本&#xff08;已實現基于 Apache Shiro 的 RBAC 權限控制&#xff09;SpringCloud 版本 1.主要依賴 名稱版本描述Angular16.2.0Angular 核心庫。PrimeNG16.2…

華為ENSP:STP和鏈路聚合的管理與配置

這里將不再過度闡述STP和鏈路聚合的理論知識&#xff0c;不清楚的同學可以去觀看Cisco文章中的理論知識 理論知識https://blog.csdn.net/2301_76341691/article/details/145166547?fromshareblogdetail&sharetypeblogdetail&sharerId145166547&sharereferPC&…

【PyCharm】連接 Git

【PyCharm】相關鏈接 【PyCharm】連接 Git【PyCharm】連接Jupyter Notebook【PyCharm】快捷鍵使用【PyCharm】遠程連接Linux服務器【PyCharm】設置為中文界面 要在 PyCharm 中連接 Git&#xff0c;確保您的開發環境已經安裝了 Git&#xff0c;并且 PyCharm 能夠訪問它。 以下…

dl學習筆記:(4)簡單神經網絡

&#xff08;1&#xff09;單層正向回歸網絡 bx1x2z100-0.2110-0.05101-0.051110.1 接下來我們用代碼實現這組線性回歸數據 import torch x torch.tensor([[1,0,0],[1,1,0],[1,0,1],[1,1,1]], dtype torch.float32) z torch.tensor([-0.2, -0.05, -0.05, 0.1]) w torch.…

三、華為交換機 Hybrid

一、Hybrid功能 Hybrid口既可以連接普通終端的接入鏈路&#xff08;類似于Access接口&#xff09;&#xff0c;又可以連接交換機間的干道鏈路&#xff08;類似于Trunk接口&#xff09;。它允許多個VLAN的幀通過&#xff0c;并可以在出接口方向將某些VLAN幀的標簽剝掉&#xff0…