답안 #52658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52658 2018-06-26T10:45:50 Z Alexa2001 Potemkin cycle (CEOI15_indcyc) C++17
30 / 100
218 ms 7156 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int Nmax = 1005;

bool edge[Nmax][Nmax], S[Nmax], used[Nmax];
int comp[Nmax], t[Nmax];
int x, y, n, m, i, C;
vector<int> v[Nmax];

struct Forest
{
    int t[2*Nmax];

    void clear()
    {
        iota(t, t+2*n+1, 0);
    }

    int boss(int x)
    {
        if(t[x] == x) return x;
        return t[x] = boss(t[x]);
    }

    void unite(int x, int y)
    {
        x = boss(x), y = boss(y);
        if(x == y) return;
        t[x] = y;
    }
} F;

void dfs(int node)
{
    used[node] = 1;
    comp[node] = C;
    for(auto it : v[node])
        if(!used[it]) dfs(it);
}

void path(int start, int finish)
{
    memset(t, -1, sizeof(t));
    t[start] = 0;

    queue<int> q;
    q.push(start);

    int node;
    while(q.size() && t[finish] == -1)
    {
        node = q.front();
        q.pop();

        for(auto it : v[node])
            if(t[it] == -1)
            {
                if(it == finish)
                {
                    t[finish] = node;
                    break;
                }
                else if(S[it]) continue;

                t[it] = node;
                q.push(it);
            }
    }

    assert(t[finish] != -1);

    while(finish)
    {
        cout << finish << ' ';
        finish = t[finish];
    }
}

void solve()
{
    int node, i;
    for(node = 1; node <= n; ++node)
    {
        memset(used, 0, sizeof(used));
        memset(S, 0, sizeof(S));
        memset(comp, 0, sizeof(comp));

        for(auto it : v[node]) used[it] = 1, S[it] = 1;
        used[node] = 1, S[node] = 1;

        C = 0;
        for(i=1; i<=n; ++i)
            if(!used[i])
            {
                ++C;
                dfs(i);
            }

        F.clear();

        for(auto x : v[node])
            for(auto y : v[x])
                if(!S[y])
                    F.unite(x, n + comp[y]);

        for(auto x : v[node])
            for(auto y : v[node])
                if(x != y && !edge[x][y] && F.boss(x) == F.boss(y))
                {
                    path(x, y);
                    cout << node << '\n';
                    return;
                }
    }
    cout << "no\n";
}

int main()
{
  //  freopen("input", "r", stdin);
  //  freopen("output", "w", stdout);
    cin.sync_with_stdio(false);

    cin >> n >> m;
    for(i=1; i<=m; ++i)
    {
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
        edge[x][y] = edge[y][x] = 1;
    }

    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 3 ms 616 KB Output is correct
4 Correct 3 ms 616 KB Output is correct
5 Correct 4 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 628 KB Output is correct
2 Runtime error 4 ms 940 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1128 KB Output is correct
2 Runtime error 4 ms 1276 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1596 KB Output is correct
2 Correct 4 ms 1596 KB Output is correct
3 Runtime error 7 ms 1896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 4532 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 17 ms 4576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 5004 KB Output is correct
2 Correct 218 ms 5712 KB Output is correct
3 Runtime error 37 ms 7156 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -