Submission #987009

#TimeUsernameProblemLanguageResultExecution timeMemory
987009PyqeThousands Islands (IOI22_islands)C++17
11.90 / 100
42 ms12380 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<long long> al[100069],al2[100069]; bitset<100069> vtd,vtd2; void dfs2(long long x) { long long i,sz=al2[x].size(),l; for(i=0;i<sz;i++) { l=al2[x][i]; dfs2(l); } an[x]=0; al2[x].clear(); cyc[x]=max(cyc[x],1ll); } void dfs(long long x) { long long i,sz=al[x].size(),l; vtd[x]=1; vtd2[x]=1; for(i=0;i<sz;i++) { l=al[x][i]; if(!vtd[l]) { dh[l]=dh[x]+1; dfs(l); if(dh[an[l]]>dh[an[x]]) { an[x]=an[l]; al2[x].clear(); } if(an[l]==an[x]) { al2[x].push_back(l); } } if(vtd2[l]) { if(dh[l]>dh[an[x]]) { an[x]=l; al2[x].clear(); } } else { cyc[x]=min(cyc[x]+cyc[l],2ll); } if(an[x]==x) { dfs2(x); } } vtd2[x]=0; } 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); } dh[0]=-1; dfs(1); return cyc[1]==2; }
#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...