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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #628 (Div. 2) F. Ehab‘s Last Theorem dfs树

發布時間:2023/12/4 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #628 (Div. 2) F. Ehab‘s Last Theorem dfs树 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

傳送門

文章目錄

  • 題意:
  • 思路:

題意:

給你個nnn個點mmm條邊的圖,可以選擇完成以下兩個任務中的一個:
(1)(1)(1)找出大小恰好為n\sqrt nn?的一個獨立集。
(2)(2)(2)找出一個長度≥n\ge \sqrt nn?的一個環。
n≤1e5,m≤2e5n\le 1e5,m\le 2e5n1e5,m2e5。

思路:

我們構造出一顆dfs樹,這棵樹有一個很重要的性質就是所有非樹邊鏈接的兩個點都是一個樹上的點以及這個點的后代。所以我們可與邊建樹邊找環,可以直接用vectorvectorvector存下來這條鏈上的編號,輸出的話倒著輸出即可。
如果找不到這樣的環,那么每個點的非樹邊一定不超過limit?2limit-2limit?2個(limit=nlimit=\sqrt nlimit=n?),因為如果>limit?2>limit-2>limit?2的話,那么至少存在limit+1limit+1limit+1條非樹邊,那么一定可形成一個大小≥limit\ge limitlimit的一個環,所以得證。
既然非樹邊一定不超過limit?2limit-2limit?2個,那么我們對每個點染色,當選了一個點的時候,那么與它相鄰的點就標記為不選,最終一定可選出一個大小正好為n\sqrt nn?的獨立集。
所以分情況討論就好啦。

// Problem: F. Ehab's Last Theorem // Contest: Codeforces - Codeforces Round #628 (Div. 2) // URL: https://codeforces.com/contest/1325/problem/F // Memory Limit: 256 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native") //#pragma GCC optimize(2) #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<map> #include<cmath> #include<cctype> #include<vector> #include<set> #include<queue> #include<algorithm> #include<sstream> #include<ctime> #include<cstdlib> #define X first #define Y second #define L (u<<1) #define R (u<<1|1) #define pb push_back #define mk make_pair #define Mid (tr[u].l+tr[u].r>>1) #define Len(u) (tr[u].r-tr[u].l+1) #define random(a,b) ((a)+rand()%((b)-(a)+1)) #define db puts("---") using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); } //void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); } //void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII;const int N=300010,M=N*4,mod=1e9+7,INF=0x3f3f3f3f; const double eps=1e-6;int n,m; vector<int>v[N],now,ans; int depth[N],limit; bool st[N];void dfs(int u) {now.pb(u);depth[u]=now.size();for(auto x:v[u]) {if(!depth[x]) dfs(x);else if(depth[u]-depth[x]>=limit-1) {printf("2\n");printf("%d\n",depth[u]-depth[x]+1);for(int i=1;i<=depth[u]-depth[x]+1;i++) printf("%d ",now.back()),now.pop_back();puts("");exit(0);}}if(!st[u]) {for(auto x:v[u]) st[x]=1;ans.pb(u);}now.pop_back(); }int main() { // ios::sync_with_stdio(false); // cin.tie(0);scanf("%d%d",&n,&m);limit=sqrt(n);limit+=(limit*limit!=n);while(m--) {int a,b; scanf("%d%d",&a,&b);v[a].pb(b); v[b].pb(a);}dfs(1);printf("1\n");for(int i=0;i<ans.size()&&i<limit;i++) printf("%d ",ans[i]);puts("");return 0; } /**/

總結

以上是生活随笔為你收集整理的Codeforces Round #628 (Div. 2) F. Ehab‘s Last Theorem dfs树的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。