This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "september.h"
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define OYY LLONG_MAX
#define mod 1000000007
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR for(int i=1;i<=n;i++)
#define mid (start+end)/2
#define lim 300005
#define fi first
#define se second
typedef long long lo;
int n,m;
int par[lim],dizi[lim],mp[lim],sz[lim];
inline int find(int node){
if(node==par[node])return node;
return par[node]=find(par[node]);
}
inline void uni(int node1,int node2){
//cout<<node1<<" "<<node2<<endl;
int par1=find(node1);
int par2=find(node2);
if(par1==par2)return ;
if(sz[par1]<sz[par2])swap(par1,par2);
sz[par1]+=sz[par2];
par[par2]=par1;
}
int solve(int N,int M,std::vector<int> F,std::vector<std::vector<int>> S){
n=N;
m=M;
FOR{
par[i-1]=i-1;
sz[i-1]=1;
}
for(int i=0;i<m;i++){
for(int j=0;j<n-1;j++){
dizi[j]=j;
mp[S[i][j]]=j;
}
for(int j=0;j<n-1;j++){
int anc=F[S[i][j]];
if(anc==0)continue;
dizi[j]=min(dizi[j],dizi[mp[anc]]);
}
for(int j=n-2;j>=0;j--){
if(j==n-2)continue;
dizi[j]=min(dizi[j],dizi[j+1]);
if(dizi[j]==dizi[j+1]){
uni(S[i][j],S[i][j+1]);
}
}
}
set<int> st;
for(int i=1;i<n;i++){
st.insert(find(i));
}
return st.size();
}
/*
int32_t main(){
faster
cin>>n>>m;
vector<int> v1;
vector<vector<int>> v2;
FOR{
int x;cin>>x;
v1.push_back(x);
}
for(int i=1;i<=m;i++){
vector<int>tut;
for(int j=1;j<n;j++){
int x;cin>>x;
tut.push_back(x);
}
v2.push_back(tut);
}
cout<<solve(n,m,v1,v2)<<'\n';
return 0;
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |