Submission #1078960

# Submission time Handle Problem Language Result Execution time Memory
1078960 2024-08-28T08:42:04 Z LIF Stranded Far From Home (BOI22_island) C++14
0 / 100
745 ms 19796 KB
#include<bits/stdc++.h>
using namespace std;
int n,m;
int head[500005];
int cnt = 0;
long long int a[500005];
int last[500005];
long long int siz[500005];
set<pair<int,int>> s;
struct edg
{
    int to;
    int next;
}edge[500005];
void add(int x,int y)
{
    cnt++;
    edge[cnt].to = y;
    edge[cnt].next = head[x];
    head[x] = cnt;
}
bool vis[500005];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        add(x,y);
        add(y,x);
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)vis[j] = false;
        vis[i] = true; // 以i開始,做bfs;
        int cnt = 0;
        pair<int,int> pp = make_pair(a[i],i);
        s.insert(pp);
        int nowval = 0;
        while(s.empty() == false)
        {
            auto it = (*s.begin());
            int id = it.second;
            if(nowval >= it.first || it.second == i)nowval += it.first;
            else break;
            cnt++;
            s.erase(s.begin());
            for(int j=head[id];j!=0;j=edge[j].next)
            {
                int to = edge[j].to;
                if(vis[to] == true)continue;
                vis[to] = true;
                pair<int,int> nw = make_pair(a[to],to);
                s.insert(nw);
            }
        }
        if(cnt >= n)last[i] = 1;
    }
    for(int i=1;i<=n;i++)cout<<last[i];
    cout<<endl;


    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 2 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 713 ms 18944 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 656 ms 19796 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 745 ms 19544 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 2 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -