답안 #877594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
877594 2023-11-23T10:53:56 Z vjudge1 Stranded Far From Home (BOI22_island) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

vector<vector<int> > graph;
vector<ll> sub;
vector<bool> ans;
vector<int> val;

void get_sub(int u, int p) {
    sub[u] = val[u];

    for(int &v : graph[u]) {
        if(v == p) continue;
        dfs(v, u);
        sub[u] += sub[v];
    }
}

void dfs(int u, int p) {
    if(sub[u] >= val[p] && ans[p] == 1) ans[u] = 1;

    for(int &v : graph[u]) {
        if(v == p) continue;
        dfs(v, u);
    }
}

int32_t main() {
    setIO();

    int n, m;
    cin >> n >> m;
    val.resize(n+1);
    for(int i=1; i<=n; i++) cin >> val[i];

    graph.resize(n+1);
    for(int i=0; i<m; i++) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    if(n <= 2000 && m <= 2000) {
        auto dijkstra = [&](int a) {
            //cout << a << ": \n";
            int cnt = 0;
            ll total = 0;
            vector<bool> vis(n+1);
            priority_queue<pll, vector<pll>, greater<pll> > pq;
            pq.push({ 0, a });

            while(!pq.empty()) {
                int u = pq.top().second;
                pq.pop();

                //cout << u << '\n';

                if(vis[u] || (total < val[u] && u != a)) continue;
                vis[u] = true;
                total += val[u];
                cnt++;

                for(int &v : graph[u]) {
                    if(vis[v]) continue;
                    pq.push({ val[v], v });
                }
            }

            return (cnt == n);
        };

        for(int i=1; i<=n; i++)
            cout << dijkstra(i);
        return 0;
    }

    sub.resize(n+1);
    ans.resize(n+1);

    get_sub(1, 0);
    ans[1] = 1;
    dfs(1, 1);

    for(int i=1; i<=n; i++)
        cout << ans[i];
    return 0;
}

Compilation message

island.cpp: In function 'void get_sub(int, int)':
island.cpp:40:9: error: 'dfs' was not declared in this scope; did you mean 'ffs'?
   40 |         dfs(v, u);
      |         ^~~
      |         ffs