답안 #987294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987294 2024-05-22T14:05:33 Z batsukh2006 Stranded Far From Home (BOI22_island) C++17
10 / 100
191 ms 5148 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]>=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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 144 ms 596 KB Output is correct
5 Correct 152 ms 604 KB Output is correct
6 Correct 171 ms 576 KB Output is correct
7 Correct 134 ms 344 KB Output is correct
8 Correct 111 ms 348 KB Output is correct
9 Correct 191 ms 856 KB Output is correct
10 Correct 49 ms 344 KB Output is correct
11 Correct 48 ms 344 KB Output is correct
12 Correct 42 ms 600 KB Output is correct
13 Correct 89 ms 348 KB Output is correct
14 Correct 89 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 69 ms 5148 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 49 ms 5124 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 49 ms 5136 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 144 ms 596 KB Output is correct
5 Correct 152 ms 604 KB Output is correct
6 Correct 171 ms 576 KB Output is correct
7 Correct 134 ms 344 KB Output is correct
8 Correct 111 ms 348 KB Output is correct
9 Correct 191 ms 856 KB Output is correct
10 Correct 49 ms 344 KB Output is correct
11 Correct 48 ms 344 KB Output is correct
12 Correct 42 ms 600 KB Output is correct
13 Correct 89 ms 348 KB Output is correct
14 Correct 89 ms 604 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Incorrect 69 ms 5148 KB Output isn't correct
18 Halted 0 ms 0 KB -