Submission #959639

# Submission time Handle Problem Language Result Execution time Memory
959639 2024-04-08T14:44:37 Z Bidoneczek11 Stranded Far From Home (BOI22_island) C++14
10 / 100
1000 ms 26392 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define nd second
#define st first
#define sz size
#define forr(i, n) for(int i=1;i<=n;i++)
const ll infl=1e18+90;
const int inf=1e9+90;
const int roz=2e5+93;

vector<pair<int,int> > wek;
vector<int> graf[roz];
int sum=0, odp[roz], odw[roz], n, val[roz];

void bfs(pair<int, int>  a)
{
    //cerr<<"wszedken\n";
    //cerr<<"a.st "<<a.st<<" a.nd "<<a.nd<<"\n";
    for(int i=1;i<=n;i++) odw[i]=0;
    int x=a.st, y=a.nd;
    priority_queue<pair<int,int> > kol;
    while(!kol.empty()) kol.pop();
    odw[y]=1;
    for(auto it:graf[y])
    {
        kol.push({-val[it], it});
    }
    while(!kol.empty())
    {
        //cerr<<"xdd\n";
        pair<int,int> b=kol.top();
        b.st=-b.st;
        kol.pop();
        //cerr<<"wlazlem dla b= "<<b.st<<" "<<b.nd<<" x = "<<x<<" "<<odw[b.nd]<<"\n";
        if(odw[b.nd]==1) continue;
        odw[b.nd]=1;
        if(b.st>x) break;
        x+=b.st;
        //cerr<<"dodalem\n";
        for(auto it:graf[b.nd])
        {
            if(odw[it]==0)
            {
                kol.push({-val[it], it});
            }
        }
    }
    //cerr<<"wyszedlem\n";
    if(x==sum) odp[y]=1;
    return;
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
        wek.pb({val[i], i});
        sum+=val[i];
    }
    sort(wek.begin(), wek.end());
    for(int i=1;i<=m;i++)
    {
        int a, b;
        cin>>a>>b;
        graf[a].pb(b);
        graf[b].pb(a);
    }
    for(int i=n-1;i>=0;i--)
    {
        bfs(wek[i]);
    }
    for(int i=1;i<=n;i++)
    {
        cout<<odp[i];
    }
    cout<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 196 ms 9820 KB Output is correct
5 Correct 134 ms 9828 KB Output is correct
6 Correct 285 ms 9832 KB Output is correct
7 Correct 199 ms 9816 KB Output is correct
8 Correct 145 ms 9816 KB Output is correct
9 Correct 197 ms 9848 KB Output is correct
10 Correct 50 ms 9820 KB Output is correct
11 Correct 46 ms 9820 KB Output is correct
12 Correct 42 ms 9820 KB Output is correct
13 Correct 82 ms 9816 KB Output is correct
14 Correct 84 ms 9816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Execution timed out 1082 ms 26392 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Execution timed out 1036 ms 24640 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Execution timed out 1075 ms 25460 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 196 ms 9820 KB Output is correct
5 Correct 134 ms 9828 KB Output is correct
6 Correct 285 ms 9832 KB Output is correct
7 Correct 199 ms 9816 KB Output is correct
8 Correct 145 ms 9816 KB Output is correct
9 Correct 197 ms 9848 KB Output is correct
10 Correct 50 ms 9820 KB Output is correct
11 Correct 46 ms 9820 KB Output is correct
12 Correct 42 ms 9820 KB Output is correct
13 Correct 82 ms 9816 KB Output is correct
14 Correct 84 ms 9816 KB Output is correct
15 Correct 2 ms 9560 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Execution timed out 1082 ms 26392 KB Time limit exceeded
18 Halted 0 ms 0 KB -