답안 #646698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646698 2022-09-30T12:07:09 Z Tenis0206 Stranded Far From Home (BOI22_island) C++11
0 / 100
1000 ms 14684 KB
#include <bits/stdc++.h>

using namespace std;

int n,m;
int s[200005];

vector<int> G[200005];

bool sel[200005],reached[200005];

bool check(int nod)
{
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> h;
    for(int i=1;i<=n;i++)
    {
        sel[i] = false;
        reached[i] = false;
    }
    sel[nod] = true;
    reached[nod] = true;
    int nr = s[nod];
    for(auto it : G[nod])
    {
        h.push({s[it],it});
        sel[it] = true;
    }
    for(int i=1;i<n;i++)
    {
        int nod = h.top().second;
        h.pop();
        if(nr < s[nod])
        {
            break;
        }
        reached[nod] = true;
        nr += s[nod];
        for(auto it : G[nod])
        {
            if(sel[it])
            {
                continue;
            }
            h.push({s[it],it});
            sel[it] = true;
        }
    }
    bool ok = true;
    for(int i=1;i<=n;i++)
    {
        ok &= reached[i];
    }
    return ok;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    string s;
    for(int i=1;i<=n;i++)
    {
        s.push_back(check(i) + '0');
    }
    cout<<s<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 5028 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 5 ms 5036 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Execution timed out 1018 ms 14652 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4984 KB Output is correct
2 Execution timed out 1029 ms 14588 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5080 KB Output is correct
2 Execution timed out 1031 ms 14684 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 5028 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Incorrect 5 ms 5036 KB Output isn't correct
5 Halted 0 ms 0 KB -