Submission #830312

# Submission time Handle Problem Language Result Execution time Memory
830312 2023-08-19T03:07:50 Z Warinchai Stranded Far From Home (BOI22_island) C++14
0 / 100
1000 ms 17796 KB
#include<bits/stdc++.h>
using namespace std;
int ar[200005];
vector<int>v[200005];
int vis[200005];
int n,m;
int check(int i){
    for(int i=1;i<=n;i++){
        vis[i]=0;
    }
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >pq;
    pq.push({ar[i],i});
    vis[i]=1;
    long long power=0;
    int hv=0;
    while(!pq.empty()){
        hv++;
        int np=pq.top().first;
        int x=pq.top().second;
        //cout<<x<<" "<<power<<endl;
        pq.pop();
        if(x==i||power>=np){
            power+=np;
            for(int j=0;j<v[x].size();j++){
                if(vis[v[x][j]]==1){
                    continue;
                }
                vis[v[x][j]]=1;
                pq.push({ar[v[x][j]],v[x][j]});
            }
        }else{
            break;
        }
    }
    if(hv==n){
        return 1;
    }else{
        return 0;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>ar[i];
    }
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=1;i<=n;i++){
        cout<<check(i);
    }
}

Compilation message

island.cpp: In function 'int check(int)':
island.cpp:24:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |             for(int j=0;j<v[x].size();j++){
      |                         ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 2 ms 5028 KB Output is correct
4 Correct 150 ms 5124 KB Output is correct
5 Correct 136 ms 5132 KB Output is correct
6 Correct 179 ms 5116 KB Output is correct
7 Correct 140 ms 5116 KB Output is correct
8 Correct 98 ms 5100 KB Output is correct
9 Incorrect 162 ms 5140 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5032 KB Output is correct
2 Correct 0 ms 4948 KB Output is correct
3 Execution timed out 1084 ms 17796 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5032 KB Output is correct
2 Execution timed out 1080 ms 17184 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5028 KB Output is correct
2 Execution timed out 1075 ms 17292 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 2 ms 5028 KB Output is correct
4 Correct 150 ms 5124 KB Output is correct
5 Correct 136 ms 5132 KB Output is correct
6 Correct 179 ms 5116 KB Output is correct
7 Correct 140 ms 5116 KB Output is correct
8 Correct 98 ms 5100 KB Output is correct
9 Incorrect 162 ms 5140 KB Output isn't correct
10 Halted 0 ms 0 KB -