답안 #50955

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50955 2018-06-15T09:18:07 Z aquablitz11 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "garden.h"
using namespace std;

const int N = 150010;
const int INF = 2e9;

vector<int> mn[N], G[2*N];
int nxt[2*N], deg[2*N], h[2*N], ph[2*N];
bool comp[2*N][3];

void expand(int u, int c, int s, int d=0, int p=-INF)
{
    if (comp[u][c])
        return;
    if (deg[u] != 1 && (u == 2*s || u == 2*s+1))
        p = 0;
    h[u] = d, ph[u] = p;
    comp[u][c] = true;
    for (auto v : G[u])
        expand(v, c, s, d+1, p+1);
}

void count_routes(int n, int m, int p, int R[][2], int q, int K[])
{
    // find min and second-min
    for (int i = 0; i < m; ++i) {
        int u = R[i][0], v = R[i][1];
        if (mn[u].size() < 2)
            mn[u].push_back(v);
        if (mn[v].size() < 2)
            mn[v].push_back(u);
    }

    // completely second-min
    for (int i = 0; i < n; ++i) {
        if (mn[i].size() == 0) continue;
        if (mn[i].size() == 1) mn[i].push_back(mn[i].back());
    }

    // find nxt of each node
    for (int i = 0; i < n; ++i) {
        if (mn[i].size() == 0) continue;
        // normal node
        int j = mn[i][0];
        if (mn[j][0] != i) nxt[2*i] = 2*j;
        else nxt[2*i] = 2*j+1;
        // walked node
        j = mn[i][1];
        if (mn[j][0] != i) nxt[2*i+1] = 2*j;
        else nxt[2*i+1] = 2*j+1;
    }

    // find degree and make reversed graph: G
    for (int u = 0; u < 2*n; ++u) {
        ++deg[nxt[u]];
        G[nxt[u]].push_back(u);
    }

    // find cycle
    queue<int> Q;
    for (int u = 0; u < 2*n; ++u) {
        if (deg[u] == 0)
            Q.push(u);
    }
    while (!Q.empty()) {
        int u = Q.front();
        Q.pop();
        if (--deg[nxt[u]] == 0)
            Q.push(nxt[u]);
    }

    // expand
    expand(2*p, 1, p);
    expand(2*p+1, 2, p);

    // find cycle size for 2*p and 2*p+1 (just in case they're different)
    int c1 = 0, u = 2*p;
    if (deg[u] == 1) {
        do {
            ++c1;
            u = nxt[u];
        } while (u != 2*p);
    }

    int c2 = 0;
    u = 2*p+1;
    if (deg[u] == 1) {
        do {
            ++c2;
            u = nxt[u];
        } while (u != 2*p+1);
    }

    // answer each query
    for (int i = 0; i < q; ++i) {
        int k = K[i], cnt = 0;
        for (int j = 0; j < n; ++j) {
            int u = 2*j;
            bool ans = ph[u] == K[i];
            if (comp[u][1])
                ans |= (c1 > 0 && k-h[u] >= 0 && (k-h[u])%c1 == 0);
            if (comp[u][2])
                ans |= (c2 > 0 && k-h[u] >= 0 && (k-h[u])%c2 == 0);
            if (ans) ++cnt;
        }
        answer(cnt);
    }

}

Compilation message

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:107:9: error: 'answer' was not declared in this scope
         answer(cnt);
         ^~~~~~
garden.cpp:107:9: note: suggested alternative: 'assert'
         answer(cnt);
         ^~~~~~
         assert