Submission #987059

#TimeUsernameProblemLanguageResultExecution timeMemory
987059PyqeThousands Islands (IOI22_islands)C++17
35 / 100
127 ms39172 KiB
#include <bits/stdc++.h> #include "islands.h" using namespace std; #define mp make_pair #define fr first #define sc second long long n,m,dh[100069],an[100069],cyc[100069]; vector<pair<long long,long long>> al[100069],nx[100069],nx2[100069]; vector<long long> vl[100069]; bitset<100069> vtd,vtd2; pair<long long,long long> pr[100069]; void dfs(long long x) { long long i,j,sz=al[x].size(),sz2,k,l,p; vtd[x]=1; vtd2[x]=1; for(i=0;i<sz;i++) { l=al[x][i].fr; p=al[x][i].sc; if(!vtd[l]) { dh[l]=dh[x]+1; pr[l]={x,p}; dfs(l); } if(vtd2[l]) { if(dh[l]>dh[an[x]]) { an[x]=l; nx[x]={{l,p}}; } } else { cyc[x]=min(cyc[x]+cyc[l],2ll); if(cyc[l]) { nx2[x].push_back({l,p}); } if(vl[x].empty()) { if(dh[an[l]]>dh[an[x]]) { an[x]=an[l]; nx[x]={{l,p}}; } } else { if(!cyc[l]) { cyc[x]=min(cyc[x]+1,2ll); nx[x].push_back({l,p}); } sz2=vl[x].size(); for(j=0;j<sz2;j++) { k=vl[x][j]; cyc[k]=max(cyc[k],1ll); } vl[x].clear(); } } } vtd2[x]=0; if(vtd2[an[x]]) { vl[an[x]].push_back(x); } } variant<bool,vector<int>> find_journey(int on,int om,vector<int> ka,vector<int> la) { long long i,k,l; n=on; m=om; for(i=1;i<=m;i++) { k=ka[i-1]+1; l=la[i-1]+1; al[k].push_back({l,i}); } dh[0]=-1; dfs(1); if(cyc[1]!=2) { return false; } return true; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...