CF 1325F - Ehab's Last Theorem

首先:

无向图的dfs树无横边

这很显然,因为若有u->v 为横边,那么v早就从这条边过来找u了...矛盾

设 \(k = ceil( \sqrt{n} )\)

接下来跑dfs树,如果有回边使得环大于等于k,就输出环。

否则,说明一个问题:所有点的回边的数量都小于k(不然一定能找到环了,鸽巢原理~)

于是,可以不停自底向上地选取点为独立集点,同时把它的领边都标记为不能取为独立集。

结果一定至少有k个独立集点。

为什么? 因为前面说了,所有点的回边的数量都小于k,这样取点,每去一次点,最多标记k-1个点为非独立集。

代码中,flag[i] = 1 表示\(i\)已经标为不是独立集点。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 1e5+5;
bool flag[N];
int fa[N], dep[N];

int n,m,k;
vector<int> G[N];

void dfs(int x,int f,int d) {
    dep[x] = d;
    fa[x] = f;
    for(auto y:G[x]) {
        if(dep[y]==0)
            dfs(y,x,d+1);
        if(dep[x]-dep[y]+1>=k) {
            cout<<2<<endl;
            cout<<dep[x]-dep[y]+1<<endl;
            cout<<y<<" ";
            int z = x;
            while(z!=y) {
                cout<<z<<" ";
                z = fa[z];
            }
            exit(0);
        }
    }
    if(!flag[x])
        for(auto y:G[x]) {
            flag[y] = 1;
        }
}

int main() {
    ios::sync_with_stdio(0);
    cin>>n>>m;
    while(k*k<n) k++;

    for(int i=0,a,b;i<m;i++) {
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(1,0,1);
    cout<<1<<endl;
    for(int i=1; k; i++) {
        if(flag[i]) continue;
        cout<<i<<" ";
        k--;
    }
    return 0;
}

CF 1325F - Ehab's Last Theorem

原文地址:https://www.cnblogs.com/scnucjh/p/12624151.html

时间: 2024-08-30 16:28:20

CF 1325F - Ehab's Last Theorem的相关文章

CF D. Ehab and the Expected XOR Problem 贪心+位运算

code: #include <bits/stdc++.h> #define N 1000000 #define setIO(s) freopen(s".in","r",stdin) using namespace std; int vis[N],b[N]; void solve() { int n,m,i,j,cur=1,cnt=0; memset(vis,0,sizeof(vis)); scanf("%d%d",&n,&a

cf 1174 D Ehab and the Expected XOR Problem

cf 1174 D Ehab and the Expected XOR Problem 题意 在1~\(2^n\)范围内找到一个最长的序列,使得该序列的每一个子串异或后不等于0和x 题解 假设该序列为a,那么前缀异或和b[i] = a[i]^a[i-1]^...^a[0],如果b之间异或都不会等于0和x,那么a之间也不会. #include <cstdio> #include <cstring> int main() { int n, x; while(~scanf("%

CF 862C Mahmoud and Ehab and the xor(异或)

题目链接:http://codeforces.com/problemset/problem/862/C 题目: Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a n

微信 {&quot;errcode&quot;:40029,&quot;errmsg&quot;:&quot;invalid code, hints: [ req_id: Cf.y.a0389s108 ]&quot;}

{"errcode":40029,"errmsg":"invalid code, hints: [ req_id: Cf.y.a0389s108 ]"} 问题:微信网页授权后,获取到 openid 了,一刷新又没了 微信网页授权获取到的 code 只能使用一次(5分钟内有效),使用一次后,马上失效. 页面授权跳转成功,根据 code 也换取到 openid 了. 此时刷新页面,并不会再次进行授权,而是直接刷新了一下上一次授权跳转后的链接,带的还是

计算理论中的莱斯定理(Rice&#39;s Theorem)——证明与应用

我们给出一个在探讨不可判定性时非常有用的结论--莱斯定理(Rice's Theorem).首先,我们来看前面讨论过的几个不可判定的例子: 这些都是由图灵机识别之语言的性质.而莱斯定理告诉我们,任何由图灵机识别之语言的非平凡性质(nontrivial property)都是不可判定的. 最后通过几个例子来探讨一下莱斯定理的应用.来看看下面这个语言能否使用莱斯定理来确定其可判定性. {<M> | M是一个TM,且L(M)可由一些拥有偶数个状态的图灵机识别} 首先来确定这是否是一个语言属性,显然是的

UVA 11178 Morley&#39;s Theorem 计算几何

计算几何: 最基本的计算几何,差积  旋转 Morley's Theorem Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the line

CF with friends and user&#39;s influence considered on NYC data(updated Aug,11st)

Here is the code link: https://github.com/FassyGit/LightFM_liu/blob/master/U_F1.py I use NYC data as other experimens. The split of the training data was seperated by the timeline, and I have normalised the interaction matrix by replacing the checkin

CF 750

今天CF打的块残废了     就是一废物 A 在24点之前到 直接模拟即可 #include<stdio.h> #include<algorithm> #include<cstring> #include<string> #include<cmath> using namespace std; #define LL long long #define MAXN 1010 #define inf 1000000000.0 int main() {

CF #394 (2) 5/6

Codeforces Round #394 (Div. 2) 总结:有毒的一场比赛.做了三题,结果A被叉,B.C挂综测,还hack失败一发,第一次在CF体会到了-50分的感觉..不知道是不是人品好,比赛时room炸了,然后,unrated.. A  水题,判一下0 0,然后abs(a-b)<=1 B  水题,组个间距比较一下,但一个数的时候要判一下 C  直接暴力上的题 D  也是xjb暴力 题意:给出n,l,r, a[], p[],另有两个数组b[], c[],ci=bi-ai.l<=ai,