#include "island.h"
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdb;
typedef tuple<int,int,int,int> TP;
typedef vector<vector<ll>> mat;
const int N=3e5+5;
const ll mod=1e9+7;
int n,m,k,a[N],u[N],v[N];
int par[N],sz[N]; vector<int> g[N];
vector<int> gp[N]; // 소속되었던 그룹 번호들
map<pii,int> mp;
int fi(int x)
{
if(par[x]==x) return x;
return par[x]=fi(par[x]);
}
void un(int x,int y,int t)
{
x=fi(x); y=fi(y);
if(sz[x]<sz[y]) swap(x,y);
sz[x]+=sz[y];
par[y]=x;
for(auto &it : g[y]){
if(mp[{x,a[it]}]) continue;
gp[a[it]].push_back(x);
g[x].push_back(it);
//cout<<x<<" with "<<y<<" : "<<it<<" , "<<a[it]<<" , "<<x<<" , "<<t<<endl;
mp[{x,a[it]}]=t;
}
}
void Init(int K, std::vector<int> F, std::vector<int> S, std::vector<int> E){
n=F.size(); m=S.size(); k=K;
for(int i=0;i<n;i++) a[i+1]=F[i]+1;
for(int i=0;i<m;i++) u[i+1]=S[i]+1,v[i+1]=E[i]+1;
for(int i=1;i<=n;i++){
par[i]=i;
sz[i]=1;
gp[a[i]].push_back(i);
g[i].push_back(i);
mp[{i,a[i]}]=m+1;
}
for(int i=m;i>=1;i--){
if(fi(u[i])==fi(v[i])) continue;
un(u[i],v[i],i);
}
}
int Separate(int a,int b)
{
a++; b++;
int ans=1;
for(auto &g : gp[a]){
if(!mp[{g,b}]) continue;
else ans=max(ans,min(mp[{g,a}],mp[{g,b}]));
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1037 ms |
54324 KB |
Output is correct |
2 |
Correct |
991 ms |
54204 KB |
Output is correct |
3 |
Correct |
1018 ms |
54332 KB |
Output is correct |
4 |
Correct |
996 ms |
54972 KB |
Output is correct |
5 |
Correct |
862 ms |
54460 KB |
Output is correct |
6 |
Correct |
829 ms |
54460 KB |
Output is correct |
7 |
Correct |
889 ms |
54076 KB |
Output is correct |
8 |
Correct |
872 ms |
54328 KB |
Output is correct |
9 |
Correct |
825 ms |
54068 KB |
Output is correct |
10 |
Correct |
1081 ms |
54612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14512 KB |
Output is correct |
2 |
Correct |
14 ms |
14464 KB |
Output is correct |
3 |
Execution timed out |
5101 ms |
36916 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14512 KB |
Output is correct |
2 |
Correct |
14 ms |
14464 KB |
Output is correct |
3 |
Correct |
1037 ms |
54324 KB |
Output is correct |
4 |
Correct |
991 ms |
54204 KB |
Output is correct |
5 |
Correct |
1018 ms |
54332 KB |
Output is correct |
6 |
Correct |
996 ms |
54972 KB |
Output is correct |
7 |
Correct |
862 ms |
54460 KB |
Output is correct |
8 |
Correct |
829 ms |
54460 KB |
Output is correct |
9 |
Correct |
889 ms |
54076 KB |
Output is correct |
10 |
Correct |
872 ms |
54328 KB |
Output is correct |
11 |
Correct |
825 ms |
54068 KB |
Output is correct |
12 |
Correct |
1081 ms |
54612 KB |
Output is correct |
13 |
Execution timed out |
5101 ms |
36916 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |