답안 #69751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69751 2018-08-21T12:41:39 Z aquablitz11 Simurgh (IOI17_simurgh) C++14
13 / 100
23 ms 3388 KB
#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;

using pii = pair<int, int>;
const int N = 510;
const int M = N*(N-1)/2;

vector<pii> G[N];
vector<int> E;

int par[N];
int root(int u) {
    if (par[u] == u) return u;
    return par[u] = root(par[u]);
}
bool merge(int u, int v) {
    u = root(u), v = root(v);
    if (u == v) return false;
    par[u] = v;
    return true;
}

bool tree[M];
int ans[N];

vector<int> find_roads(int n, vector<int> U, vector<int> V)
{
    int m = U.size();
    iota(par, par+n, 0);
    fill(ans, ans+m, -1);
    for (int i = 0; i < m; ++i) {
        int u = U[i], v = V[i];
        if (merge(u, v)) {
            G[u].emplace_back(v, i);
            G[v].emplace_back(u, i);
            E.push_back(i);
            tree[i] = true;
        }
    }
    int defcnt = count_common_roads(E);
    for (int i = 0; i < m; ++i) if (!tree[i]) {
        int u = U[i], v = V[i];
        vector<int> par(n, -1);
        vector<int> ix(n, -1);
        par[u] = u;
        queue<int> Q;
        Q.push(u);
        while (!Q.empty()) {
            int s = Q.front(); Q.pop();
            if (s == v) break;
            for (auto t : G[s]) if (par[t.first] == -1) {
                par[t.first] = s;
                ix[t.first] = t.second;
                Q.push(t.first);
            }
        }
        map<int, bool> inp;
        vector<int> path;
        int s = v;
        do {
            inp[ix[s]] = true;
            path.push_back(ix[s]);
            s = par[s];
        } while (s != u);

        int typ = -1; // not -1 = found determined
        for (auto e : path) {
            if (ans[e] != -1) {
                typ = e;
                break;
            }
        }
        vector<int> other;
        for (auto e : E) {
            if (!inp[e])
                other.push_back(e);
        }
        if (typ == -1) {
            ans[i] = 0;
            for (auto e : path) {
                vector<int> q(other.begin(), other.end());
                for (auto p : path) if (p != e)
                    q.push_back(p);
                q.push_back(i);
                int cnt = count_common_roads(q);
                if (cnt-defcnt == 1)
                    ans[e] = 0, ans[i] = 1;
                else if (cnt-defcnt == -1)
                    ans[i] = 0, ans[e] = 1;
            }
            if (ans[i] == -1) ans[i] = 0;
            for (auto e : path) if (ans[e] == -1)
                ans[e] = ans[i];
        } else {
            vector<int> q(other.begin(), other.end());
            for (auto e : path) if (e != typ)
                q.push_back(e);
            q.push_back(i);
            int cnt = count_common_roads(q);
            ans[i] = ans[typ]+(cnt-defcnt);
            assert(ans[i] == 0 || ans[i] == 1);
            for (auto e : path) if (ans[e] == -1) {
                q = vector<int>(other.begin(), other.end());
                for (auto p : path) if (p != e) q.push_back(p);
                q.push_back(i);
                int cnt = count_common_roads(q);
                ans[e] = ans[i]+(defcnt-cnt);
                assert(ans[e] == 0 || ans[e] == 1);
            }
        }
    }
    vector<int> ret;
    ret.reserve(n-1);
    for (int i = 0; i < m; ++i) {
        if (ans[i] != 0)
            ret.push_back(i);
    }
    return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 248 KB correct
2 Correct 2 ms 356 KB correct
3 Correct 3 ms 560 KB correct
4 Correct 3 ms 560 KB correct
5 Correct 3 ms 560 KB correct
6 Correct 3 ms 568 KB correct
7 Correct 3 ms 568 KB correct
8 Correct 2 ms 568 KB correct
9 Correct 2 ms 568 KB correct
10 Correct 2 ms 568 KB correct
11 Correct 3 ms 572 KB correct
12 Correct 3 ms 572 KB correct
13 Correct 3 ms 572 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 248 KB correct
2 Correct 2 ms 356 KB correct
3 Correct 3 ms 560 KB correct
4 Correct 3 ms 560 KB correct
5 Correct 3 ms 560 KB correct
6 Correct 3 ms 568 KB correct
7 Correct 3 ms 568 KB correct
8 Correct 2 ms 568 KB correct
9 Correct 2 ms 568 KB correct
10 Correct 2 ms 568 KB correct
11 Correct 3 ms 572 KB correct
12 Correct 3 ms 572 KB correct
13 Correct 3 ms 572 KB correct
14 Incorrect 3 ms 572 KB WA in grader: NO
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 248 KB correct
2 Correct 2 ms 356 KB correct
3 Correct 3 ms 560 KB correct
4 Correct 3 ms 560 KB correct
5 Correct 3 ms 560 KB correct
6 Correct 3 ms 568 KB correct
7 Correct 3 ms 568 KB correct
8 Correct 2 ms 568 KB correct
9 Correct 2 ms 568 KB correct
10 Correct 2 ms 568 KB correct
11 Correct 3 ms 572 KB correct
12 Correct 3 ms 572 KB correct
13 Correct 3 ms 572 KB correct
14 Incorrect 3 ms 572 KB WA in grader: NO
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 572 KB correct
2 Correct 2 ms 572 KB correct
3 Runtime error 23 ms 3388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 248 KB correct
2 Correct 2 ms 356 KB correct
3 Correct 3 ms 560 KB correct
4 Correct 3 ms 560 KB correct
5 Correct 3 ms 560 KB correct
6 Correct 3 ms 568 KB correct
7 Correct 3 ms 568 KB correct
8 Correct 2 ms 568 KB correct
9 Correct 2 ms 568 KB correct
10 Correct 2 ms 568 KB correct
11 Correct 3 ms 572 KB correct
12 Correct 3 ms 572 KB correct
13 Correct 3 ms 572 KB correct
14 Incorrect 3 ms 572 KB WA in grader: NO
15 Halted 0 ms 0 KB -