답안 #635226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635226 2022-08-25T17:00:49 Z PanTkd Stranded Far From Home (BOI22_island) C++14
0 / 100
1000 ms 15164 KB
//
//  main.cpp
//
//  Created by Panagiotis Chadjicostas on
//  Copyright © Panagiotis Hadjicostas. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <limits>
#include <list>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

typedef int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
#ifdef px
    #define p(x) cerr<<#x<<' '<<x<<endl;
#else
    #define p(x) {}
#endif
#define F first
#define S second
#define sz size
#define ls s,m,idx<<1
#define rs m+1,e,idx<<1|1
const ll MOD=ll(1e9)+7;
const ll MAXN=2*ll(1e6);
///////////////////////////////////////////////////////////////////////
vector<vi> A;
vi V;
vi S;
ll sum=0;
void dfs(ll s){
    sum+=S[s];
    V[s]=1;
    for(auto x:A[s]){
        if(!V[x]){
            if(sum>=S[x])
                dfs(x);
        }
    }
}
bool cmp(ll x,ll y){
    if(S[x]<S[y])
        return 1;
    return 0;
}
void solve(){
    ll n,m;cin>>n>>m;
    S.assign(n+1,0);
    for(ll i=1;i<=n;i++)cin>>S[i];
    
    A.assign(n+1,vi());
    for(ll i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        A[a].push_back(b);A[b].push_back(a);
    }
    string ans;
    for(ll i=1;i<=n;i++){
        sort(A[i].begin(),A[i].end(),cmp);
        V.assign(n+1,0);
        bool f=0;
        sum=0;
        dfs(i);
        for(ll j=1;j<=n;j++){if(!V[j]){ans+='0';f=1;break;}}
        if(!f)ans+='1';
    }cout<<ans<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;//cin>>t;
    while (t--) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 3 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1081 ms 15164 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1083 ms 12856 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1093 ms 12852 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 3 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -