Submission #987295

# Submission time Handle Problem Language Result Execution time Memory
987295 2024-05-22T14:06:45 Z batsukh2006 Stranded Far From Home (BOI22_island) C++17
10 / 100
173 ms 5200 KB
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
#include<utility>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<functional>
#include<stack>
#include<limits.h>
#include<iomanip>
#include<unordered_map> 
#include<numeric>
#include<tuple>
#include<bitset>
using namespace std;
 
#define MOD 1000000007
#define int long long
#define ss second
#define ff first
#define endl '\n'
typedef pair<int,int> pp;
void solve(){
	int n,m; cin>>n>>m;
    if(n<=2000&&m<=2000){
        vector<int> v[n+1],s(n+1);
        for(int i=1; i<=n; i++) cin>>s[i];
        for(int i=1; i<=m; i++){
            int a,b; cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
        }
        int need=0;
        vector<int> dp(n+1);
        for(int i=1; i<=n; i++){
            priority_queue<pp,vector<pp>,greater<pp> > q;
            vector<bool> vis(n+1);
            q.push({s[i],i});
            need+=s[i];
            vis[i]=1;
            while(!q.empty()){
                int w=q.top().ff;
                int a=q.top().ss;
                if(w>dp[i]&&a!=i) break;
                dp[i]+=w;
                q.pop();
                for(auto node: v[a]){
                    if(!vis[node]){
                        vis[node]=1;
                        q.push({s[node],node});
                    }
                }
            }
        }
        for(int i=1; i<=n; i++){
            if(dp[i]==need) cout<<1;
            else cout<<0;
        }
    }else{
        vector<int> dp(n+1),s(n+1),p(n+1);
        for(int i=1; i<=n; i++){
            cin>>s[i];
            dp[i]=s[i];
        }
        for(int i=1; i<=m; i++){
            int a,b; cin>>a>>b;
            if(a>b) swap(a,b);
            dp[a]+=s[b];
            p[b]=a;
        }
        for(int i=2; i<=n; i++){
            if(dp[i]==dp[p[i]]) dp[p[i]]+=dp[i]-s[i];
            if(dp[i]>=dp[p[i]]) dp[i]+=dp[p[i]];
            else dp[p[i]]+=dp[i]-s[i];
        }
        for(int i=1; i<=n; i++){
            if(dp[i]>=s[1]) cout<<1;
            else cout<<0;
        }
    }
}
signed main(){
    // freopen("file.in", "r", stdin);
    // freopen("file.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int t=1;
    // cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 139 ms 348 KB Output is correct
5 Correct 130 ms 604 KB Output is correct
6 Correct 173 ms 344 KB Output is correct
7 Correct 138 ms 344 KB Output is correct
8 Correct 96 ms 348 KB Output is correct
9 Correct 166 ms 604 KB Output is correct
10 Correct 49 ms 348 KB Output is correct
11 Correct 47 ms 348 KB Output is correct
12 Correct 43 ms 604 KB Output is correct
13 Correct 89 ms 348 KB Output is correct
14 Correct 77 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 65 ms 5200 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 51 ms 5120 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 50 ms 5136 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 139 ms 348 KB Output is correct
5 Correct 130 ms 604 KB Output is correct
6 Correct 173 ms 344 KB Output is correct
7 Correct 138 ms 344 KB Output is correct
8 Correct 96 ms 348 KB Output is correct
9 Correct 166 ms 604 KB Output is correct
10 Correct 49 ms 348 KB Output is correct
11 Correct 47 ms 348 KB Output is correct
12 Correct 43 ms 604 KB Output is correct
13 Correct 89 ms 348 KB Output is correct
14 Correct 77 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Incorrect 65 ms 5200 KB Output isn't correct
18 Halted 0 ms 0 KB -