제출 #1179410

#제출 시각아이디문제언어결과실행 시간메모리
1179410IskachunStranded Far From Home (BOI22_island)C++20
0 / 100
1097 ms18712 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
void solve() {
    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    for (ll &x : a) cin >> x;
    vector<vector<ll>> g(n);
    while (m--) {
        ll u, v; cin >> u >> v;
        g[--u].push_back(--v), g[v].push_back(u);
    }
    vector<ll> vis(n);
    queue<ll> q;
    for (ll i = 0; i < n; i++) {
        vis = vector<ll> (n);
        vis[i] = 1;
        while (q.size()) q.pop();
        q.push(i);
        ll tot = a[i];
        while (q.size()) {
            ll v = q.front(); q.pop();
            //int flag = 1;
            //while (flag) {
                //flag = 0;
                for (ll u : g[v]) {
                    if (!vis[u] and a[u] <= tot) {
                        tot += a[u];
                        vis[u] = 1;
                        q.push(u), q.push(v);
                    }
                }
            //}
        }
        ll flag = 1;
        for (ll x : vis) {
            if (!x) {flag = 0; break;}
        }
        cout << flag;
    }
}

int main() {
    //freopen("filename.in", "r", stdin), freopen("filename.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t = 1; //cin >> t;
    while (t--) solve();
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...