Submission #987289

# Submission time Handle Problem Language Result Execution time Memory
987289 2024-05-22T13:57:30 Z batsukh2006 Stranded Far From Home (BOI22_island) C++17
10 / 100
170 ms 5400 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];
        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=1; i<=n; i++){
            if(dp[i]>=dp[p[i]]) dp[i]+=dp[p[i]];
            if(dp[i]==dp[p[i]]) dp[p[i]]+=dp[i];
            if(dp[i]>=dp[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 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 157 ms 596 KB Output is correct
5 Correct 130 ms 600 KB Output is correct
6 Correct 170 ms 568 KB Output is correct
7 Correct 136 ms 580 KB Output is correct
8 Correct 96 ms 348 KB Output is correct
9 Correct 164 ms 604 KB Output is correct
10 Correct 49 ms 344 KB Output is correct
11 Correct 47 ms 348 KB Output is correct
12 Correct 43 ms 604 KB Output is correct
13 Correct 90 ms 576 KB Output is correct
14 Correct 75 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 424 KB Output is correct
3 Incorrect 49 ms 5212 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 50 ms 5400 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 5204 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 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 157 ms 596 KB Output is correct
5 Correct 130 ms 600 KB Output is correct
6 Correct 170 ms 568 KB Output is correct
7 Correct 136 ms 580 KB Output is correct
8 Correct 96 ms 348 KB Output is correct
9 Correct 164 ms 604 KB Output is correct
10 Correct 49 ms 344 KB Output is correct
11 Correct 47 ms 348 KB Output is correct
12 Correct 43 ms 604 KB Output is correct
13 Correct 90 ms 576 KB Output is correct
14 Correct 75 ms 600 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 424 KB Output is correct
17 Incorrect 49 ms 5212 KB Output isn't correct
18 Halted 0 ms 0 KB -