답안 #483196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
483196 2021-10-28T06:53:53 Z abc864197532 낙하산 고리들 (IOI12_rings) C++17
0 / 100
530 ms 66260 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define X first
#define Y second
#define pii pair<int, int>
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
    cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
    for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(args...) abc("[" + string(#args) + "]", args);
#include "grader_B.cpp"
#else
#define test(args...) void(0);
#endif
const int N = 1000000;

vector <pii> edge;
vector <int> adj[N];
int n, dsu[N], cnt;
bool vis[N], cyc;

void dfs(int v, int pa) {
    vis[v] = true;
    cnt++;
    for (int u : adj[v]) if (u != pa) {
        if (!vis[u])
            dfs(u, v);
        else {
            cyc = true;
        }
    }
}

int Find(int x) {
    if (dsu[x] == x)
        return x;
    return dsu[x] = Find(dsu[x]);
}

void Init(int N) {
    n = N;
}

void Link(int a, int b) {
    adj[a].pb(b), adj[b].pb(a);
    edge.eb(a, b);
}

int check(int x) {
    iota(dsu, dsu + n, 0);
    vector <int> deg(n, 0);
    for (pii e : edge) if (e.X != x && e.Y != x) {
        if (Find(e.X) == Find(e.Y))
            return false;
        dsu[Find(e.X)] = Find(e.Y);
        deg[e.X]++, deg[e.Y]++;
    }
    for (int i = 0; i < n; ++i) if (deg[i] > 2)
        return false;
    return true;
}

int CountCritical() {
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        vis[i] = false;
        if (adj[i].size() > 3)
            return 0;
        if (adj[i].size() == 3) {
            for (int j : adj[i])
                ans += check(j);
            ans += check(i);
            return ans;
        }
    }
    int now = -1;
    for (int i = 0; i < n; ++i) if (!vis[i]) {
        cnt = 0, cyc = false;
        dfs(i, -1);
        if (cyc) {
            if (now != -1)
                return 0;
            now = cnt;
        }
    }
    return now == -1 ? n : now;
}

/*
7 13
-1
1 2
-1
0 5
-1
2 0
-1
3 2
-1
3 5
-1
4 3
-1
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23760 KB Output is correct
2 Incorrect 12 ms 24000 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 332 ms 44744 KB Output is correct
2 Incorrect 530 ms 66260 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23760 KB Output is correct
2 Incorrect 12 ms 24000 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23760 KB Output is correct
2 Incorrect 12 ms 24000 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23760 KB Output is correct
2 Incorrect 12 ms 24000 KB Output isn't correct
3 Halted 0 ms 0 KB -