<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      歡迎來到AlexZhang的博客

      人生三從境界:昨夜西風凋碧樹,獨上高樓,望盡天涯路。 衣帶漸寬終不悔,為伊消得人憔悴。 眾里尋他千百度,驀然回首,那人卻在燈火闌珊處。

      luogu P3144 [USACO16OPEN]關(guān)閉農(nóng)場Closing the Farm_Silver解題報告

      題目描述

      Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to temporarily close down his farm to save money in the meantime.

      The farm consists of NN barns connected with MM bidirectional paths between some pairs of barns (1 \leq N, M \leq 30001N,M3000). To shut the farm down, FJ plans to close one barn at a time. When a barn closes, all paths adjacent to that barn also close, and can no longer be used.

      FJ is interested in knowing at each point in time (initially, and after each closing) whether his farm is "fully connected" -- meaning that it is possible to travel from any open barn to any other open barn along an appropriate series of paths. Since FJ's farm is initially in somewhat in a state of disrepair, it may not even start out fully connected.

      FJ和他的奶牛們正在計劃離開小鎮(zhèn)做一次長的旅行,同時FJ想臨時地關(guān)掉他的農(nóng)場以節(jié)省一些金錢。

      這個農(nóng)場一共有被用M條雙向道路連接的N個谷倉(1<=N,M<=3000)。為了關(guān)閉整個農(nóng)場,F(xiàn)J 計劃每一次關(guān)閉掉一個谷倉。當一個谷倉被關(guān)閉了,所有的連接到這個谷倉的道路都會被關(guān)閉,而且再也不能夠被使用。

      FJ現(xiàn)在正感興趣于知道在每一個時間(這里的“時間”指在每一次關(guān)閉谷倉之前的時間)時他的農(nóng)場是否是“全連通的”——也就是說從任意的一個開著的谷倉開始,能夠到達另外的一個谷倉。注意自從某一個時間之后,可能整個農(nóng)場都開始不會是“全連通的”。

      輸入輸出格式

      輸入格式:

       

      The first line of input contains NN and MM. The next MM lines each describe a

      path in terms of the pair of barns it connects (barns are conveniently numbered

      1 \ldots N1N). The final NN lines give a permutation of 1 \ldots N1N

      describing the order in which the barns will be closed.

       

      輸出格式:

       

      The output consists of NN lines, each containing "YES" or "NO". The first line

      indicates whether the initial farm is fully connected, and line i+1i+1 indicates

      whether the farm is fully connected after the iith closing.

       

      輸入輸出樣例

      輸入樣例#1:
      4 3
      1 2
      2 3
      3 4
      3
      4
      1
      2
      輸出樣例#1:
      YES
      NO
      YES
      YES

      這道題有一個判連通性過程,馬上應該想到并查集這種好東西,但是我們從一個集合去拆肯定會很麻煩的,時間上也無法被允許,那么我們正難則反,既然正著推比較麻煩,那我們?yōu)槭裁床话堰@個關(guān)閉的過程倒過來想象成打開呢,剛開始都是關(guān)閉狀態(tài),然后一個個打開,最后倒著輸出即可,不多說了上代碼
      #include <cstdio>
      #include <algorithm>
      #include <cstring>
      using namespace std;
      int n,m,a[3005][3005],p[3005],check[3005],fa[3005],ans[3005];
      int find(int x){
          if(fa[x]==x) return x;
          return fa[x]=find(fa[x]);
      }
      int main(){
          scanf("%d%d",&n,&m);
          for(int i=1;i<=m;i++){
              int x,y;
              scanf("%d%d",&x,&y);
              a[x][y]=a[y][x]=1;
          }
          for(int i=1;i<=n;i++){
              fa[i]=i;
              scanf("%d",&p[i]);
          }
          for(int i=n;i>=1;i--){
              check[p[i]]=1;
              for(int j=1;j<=n;j++)
                  if(check[j]&&a[p[i]][j]){
                      //if(i==2) printf("%d %d\n",p[i],j);
                      fa[find(p[i])]=find(j);
                  }
              int cnt=0;
              for(int j=1;j<=n;j++)
                  if(check[j]&&fa[j]==j) cnt++;
              if(cnt>1) ans[i]=1;
          }
          for(int i=1;i<=n;i++)
              if(ans[i]) printf("NO\n");
              else printf("YES\n");
          return 0;
      }

       

      posted @ 2018-09-30 17:00  NGU_AlexZhang  閱讀(278)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲一区二区精品动漫| 人禽无码视频在线观看| 国产精品熟女亚洲av麻豆| 亚洲精品日韩在线丰满| 日韩精品中文字幕有码| 亚洲精品不卡av在线播放| 国产成人久久精品流白浆| 昌江| 日本一本无道码日韩精品| 亚洲国产精品成人无码区| 无码免费中文字幕视频| 国产精品自拍自在线播放| 九九热精品在线观看视频| 扒开粉嫩的小缝隙喷白浆视频| 久久综合国产色美利坚| 69精品无人区国产一区| 91国在线啪精品一区| 国产偷自视频区视频| 一个色综合色综合色综合| gogogo在线播放中国| 性一交一乱一伦一| 农村老熟妇乱子伦视频| 国产性色的免费视频网站| 称多县| 免费人成在线观看网站| 韩国V欧美V亚洲V日本V| 少妇高潮喷水正在播放| 一区二区三区av天堂| 尤物视频色版在线观看| 精品国产精品中文字幕| 精品国产久一区二区三区| 亚洲男女羞羞无遮挡久久丫| 无码国产偷倩在线播放| 日韩精品一区二区三区日韩| 久久久久国产精品熟女影院| 99精品人妻少妇一区| 九九热在线这里只有精品| 人妻aⅴ无码一区二区三区| 亚洲精品码中文在线观看| 成人一区二区不卡国产| 丰满少妇高潮惨叫久久久|