Submission #876218

# Submission time Handle Problem Language Result Execution time Memory
876218 2023-11-21T12:49:58 Z 8pete8 Stranded Far From Home (BOI22_island) C++14
0 / 100
70 ms 7112 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
#include <iomanip>  
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define ll long long    
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#pragma GCC optimize ("03,unroll-lopps")
const int mxn=2e5,inf=1e9;
vector<ppii>e;
int val[mxn+10],n,m,pa[mxn+10],sum[mxn+10];
bool ans[mxn+10];
int find(int u){
    if(pa[u]==u)return u;
    int k=find(pa[u]);
    ans[u]|=ans[k];
    return pa[u]=k;
}
void merg(int u,int v){
    int a=find(u),b=find(v);
    if(a==b)return;
    if(sum[b]<val[a])return void(ans[b]=true);
    pa[b]=a,sum[a]+=sum[b],ans[a]|=ans[b];
}
int32_t main(){
    fastio
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>val[i],sum[i]=val[i],pa[i]=i;
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;
        if(val[a]<val[b])swap(a,b);
        e.pb({val[a],{a,b}});
    }
    sort(all(e));
    for(auto i:e)merg(i.s.f,i.s.s);
    for(int i=1;i<=n;i++)find(i),cout<<(!ans[i]);
}

Compilation message

island.cpp:35:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   35 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
island.cpp:40:15: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   40 | int find(int u){
      |               ^
island.cpp:46:22: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   46 | void merg(int u,int v){
      |                      ^
island.cpp:52:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   52 | int32_t main(){
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Incorrect 65 ms 7112 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 67 ms 6896 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Incorrect 70 ms 7108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -