跳到正文

蒟蒻的蒋文轩

62859

在洛谷打开
资料、奖项与版本

资料

编号
62859
抓取

狗屁不通文章生成器

元气弹

Tarjan(求割点)

C++
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
struct Edge {
    int v, nex;
} e[1000005];
int head[200005], eum;
void addedge(int u, int v) {
    e[++eum].nex=head[u];
    head[u]=eum;
    e[eum].v=v;
}

int ans[200005], times, n, m, u, v, dfn[200005], low[200005];
void tarjan(int u, int fa) {
    dfn[u]=low[u]=++times;
    int child=0;
    for (int i=head[u]; i; i=e[i].nex) {
        int v=e[i].v;
        if (!dfn[v]) {
            tarjan(v, u);
            low[u]=min(low[u], low[v]);
            if (low[v]>=dfn[u] && u!=fa) ans[u]=true;
            if (fa==u) child++;
        }
        low[u]=min(low[u], dfn[v]);
    }
    if (child>=2 && fa==u)
        ans[u]=true;
    return;
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i=1; i<=m; i++) {
        scanf("%d%d", &u, &v);
        addedge(u, v);
        addedge(v, u);
    }
    for (int i=1; i<=n; i++)
        if (!dfn[i])
            tarjan(i, i);
    vector<int> a;
    for (int i=1; i<=n; i++)
        if (ans[i])
            a.push_back(i);
    printf("%d\n", a.size());
    for (vector<int>::iterator it=a.begin(); it!=a.end(); it++)
        printf("%d ", *it);
    return 0;
}

逆序对

C++
#include<bits/stdc++.h>
using namespace std;
long long ans=0;
int n, a[500005], s[500005];
void msort(int l, int r) {
    if (l==r) return;
    int mid=l+((r-l)>>1);
    msort(l, mid); msort(mid+1, r);
    int i=l, j=mid+1, t=l;
    while (i<=mid && j<=r)
        if (a[i]<=a[j]) s[t++]=a[i++];
        else s[t++]=a[j++],
            ans+=(long long)mid-i+1;
    while (i<=mid) s[t++]=a[i++];
    while (j<=r) s[t++]=a[j++];
    for (int i=l; i<=r; i++)
        a[i]=s[i];
}
int main() {
    scanf("%d", &n);
    for (int i=1; i<=n; i++)
        scanf("%d", &a[i]);
    msort(1, n);
    printf("%lld\n", ans);
    return 0;
}

https://www.luogu.org/blog/zhundiandexingchen/liu-lan-qi-di-zheng-que-da-kai-fang-shi

QQ:2868702244

http://iogames.space/shell-shockers

https://make.girls.moe/#/

还没有收录这位用户的文章。