彩虹20pts,求助!!!!
  • 板块P1656 炸铁路
  • 楼主CJ_LIU_XC
  • 当前回复3
  • 已保存回复3
  • 发布时间2020/10/8 10:33
  • 上次更新2023/11/5 11:36:31
查看原帖
彩虹20pts,求助!!!!
212882
CJ_LIU_XC楼主2020/10/8 10:33

RT。
放代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#define N 10010
# define forr(b, e, x) for(int i = b; i <= e; i += x)
inline int read()
{
    int ans = 0;
    char ch = getchar();
    while (!isdigit(ch) && ch != '-') ch = getchar();
    bool sign = false;
    if (ch == '-') sign = true, ch = getchar();
    while (ch >= '0' && ch <= '9') ans = ans * 10 + (ch - '0'), ch = getchar();
    return (sign == true ? -ans : ans);
}
typedef long long ll;
using namespace std;
int mp[200][200];
int dfn[N], low[N], n, m, id, cnt, f[N];
struct edge { int t, u; }g[N];
bool cmp(edge a, edge b)
{
    if (a.t != b.t) return a.u < b.u;
    return a.t < b.t;
}
inline void add(int x, int y)
{
    g[++ cnt].t = x;
    g[cnt].u = y;
}
void tarjian(int u)
{
    int c = 0, y;
    dfn[u] = low[u] = ++id;
    forr (1, n, 1)
    {
        if (!mp[u][i]) continue;
        y = i;
        if (dfn[y] && y != f[u]) low[u] = min(low[u], low[y]);
        if (!dfn[y])
        {
            f[y] = u;
            tarjian(y);
            low[u] = min(low[u], low[y]);
            if (low[y] > dfn[u]) add(u, y);
        }
    }
}
int main()
{
    int x, y;
    n = read(), m = read();
    forr (1, n, 1)
    {
        x = read(), y = read();
        mp[x][y] = mp[y][x] = 1;
    }
    forr (1, n, 1)
        if (!dfn[i])
            tarjian(i);
    sort (g + 1, g + cnt + 1, cmp);
    forr (1, cnt, 1)
        printf("%d %d\n", min(g[i].t, g[i].u), max(g[i].t, g[i].u));
    return 0;
}
2020/10/8 10:33
加载中...