QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#509574#4209. Stranded Far From Homekimmoqt#0 2ms3772kbC++202.1kb2024-08-08 16:09:582024-08-08 16:09:59

Judging History

你现在查看的是最新测评结果

  • [2024-08-08 16:09:59]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3772kb
  • [2024-08-08 16:09:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MX=4e4+5;

int N,M;
int S[MX], sz[MX];
bool act[MX], ans[MX];
vector<int> adj[MX], G[MX];

struct dsu {
        int par[MX];

        int find(int v) {
                return par[v]==v?v:par[v]=find(par[v]);
        }

        bool merge(int u, int v) {
                u=find(u), v=find(v);
                if(u==v) return false;
                par[u]=v;
                return true;
        }

        void prep() {
                for(int i=0;i<N;i++) {
                        par[i]=i;
                }
        }
} ds;

int main() {
        cin.tie(0); ios_base::sync_with_stdio(0);

        cin>>N>>M;

        for(int i=0;i<N;i++) cin>>S[i];

        for(int i=0;i<M;i++) {
                int u,v;
                cin>>u>>v;
                u--,v--;
                adj[u].push_back(v);
                adj[v].push_back(u);
        }

        ds.prep();

        vector<int> ord;
        for(int i=0;i<N;i++) ord.push_back(i);

        sort(ord.begin(),ord.end(),[&](int i, int j){
                return S[i]<S[j];
        });
        
        for(auto x:ord) {
                act[x]=true;
                for(auto u:adj[x]) {
                        if(!act[u]) continue;
                        if(ds.find(x)==ds.find(u)) continue;
                        // cout<<x<<" -> "<<ds.find(u)<<'\n';
                        G[x].push_back(ds.find(u));
                        ds.merge(u,x);
                }
        }

        reverse(ord.begin(),ord.end());

        for(int i=ord.size()-1;i>=0;i--) {
                sz[ord[i]]=S[ord[i]];
                for(auto j:G[ord[i]]) {
                        sz[ord[i]]+=sz[j];
                }
        }

        ans[ord[0]]=true;
        for(int i=0;i<ord.size();i++) {
                for(auto j:G[ord[i]]) {
                        if(sz[j]>=S[ord[i]]) ans[j]=ans[ord[i]];
                        else ans[j]=false;
                }
        }

        string res="";
        for(int i=0;i<N;i++) 
                res+=ans[i]?"1":"0";
        cout<<res<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3772kb

input:

1622 1998
29021716 740464354 721037601 759718475 973636178 59068917 294028640 285332651 203821680 397646208 488684783 448548424 565347277 112938323 832704692 837437153 508335516 167646888 798998153 86605661 820823253 705498382 116513873 672806499 522392461 568294614 457655230 647498964 577669416 506...

output:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000...

result:

wrong answer 1st lines differ - expected: '011110101110001100101101111110...1000100110101000000111111011011', found: '000000000000000000000000000000...0000000000000000000000000000000'

Subtask #2:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 2ms
memory: 3720kb

input:

200000 199999
100000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

1

result:

wrong answer 1st lines differ - expected: '100000000000000000000000000000...0000000000000000000000000000000', found: '1'

Subtask #3:

score: 0
Runtime Error

Test #30:

score: 0
Runtime Error

input:

199999 199998
758475118 758475116 758475114 758475112 758475110 758475108 758475106 758475104 758475102 758475100 758475098 758475096 758475094 758475092 758475090 758475088 758475086 758475084 758475082 758475080 758475078 758475076 758475074 758475072 758475070 758475068 758475066 758475064 758475...

output:


result:


Subtask #4:

score: 0
Runtime Error

Test #39:

score: 0
Runtime Error

input:

155555 200000
473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%