답안 #952171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952171 2024-03-23T08:30:14 Z vjudge1 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, m, p, Q, fir[N], sec[N], to[N], q[N], dis[N], cnt[N], sum[N], ans[N];
void add(int u, int v) {
    if (!fir[u])
        fir[u] = v;
    else if (!sec[u])
        sec[u] = v;
}
void dfs(int p, int ed) {
    if (dis[p] != -1)
        return;
    dis[p] = -1e9;
    if (to[p] == ed)
        dis[p] = 1;
    else {
        dfs(to[p], ed);
        if (dis[to[p]] <= -1e8)
            dis[p] = -1e9;
        else
            dis[p] = dis[to[p]] + 1;
    }
}
int main() {
    scanf("%d %d %d", &n, &m, &p);
    p++;
    for (int i = 1, u, v; i <= m; i++) {
        scanf("%d %d", &u, &v);
        u++, v++;
        add(u, v);
        add(v, u);
    }
    for (int i = 1; i <= n; i++) {
        to[i] = (fir[fir[i]] == i) * n + fir[i];
        if (!sec[i])
            to[i + n] = to[i];
        else
            to[i + n] = (fir[sec[i]] == i) * n + sec[i];
    }
    scanf("%d", &Q);
    for (int i = 1; i <= Q; i++) scanf("%d", &q[i]);
    for (int i = 0; i <= 1; i++) {
        memset(dis, -1, sizeof(dis));
        memset(sum, 0, sizeof(sum));
        memset(cnt, 0, sizeof(cnt));
        int now = i * n + p;
        for (int j = 1; j <= n; j++) dfs(j, now);
        dfs(now, now);
        for (int j = 1; j <= n; j++)
            if (dis[j] > 0) {
                sum[dis[j]]++;
                if (dis[now] > 0)
                    cnt[dis[j] % dis[now]]++;
            }
        if (dis[now] > 0)
            for (int j = dis[now]; j < 2 * n; j++) sum[j] += sum[j - dis[now]];
        for (int j = 1; j <= Q; j++)
            if (q[j] < 2 * n)
                ans[j] += sum[q[j]];
            else if (dis[now] > 0)
                ans[j] += cnt[q[j] % dis[now]];
    }
    for (int i = 1; i <= Q; i++) printf("%d\n", ans[i]);
}

Compilation message

garden.cpp: In function 'int main()':
garden.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d %d %d", &n, &m, &p);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
garden.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
garden.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d", &Q);
      |     ~~~~~^~~~~~~~~~
garden.cpp:42:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     for (int i = 1; i <= Q; i++) scanf("%d", &q[i]);
      |                                  ~~~~~^~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccDS6IES.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccBAstLT.o:garden.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccDS6IES.o: in function `main':
grader.cpp:(.text.startup+0x3f): undefined reference to `count_routes(int, int, int, int (*) [2], int, int*)'
collect2: error: ld returned 1 exit status