# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
332393 | nicholask | Split the Attractions (IOI19_split) | C++14 | 6 ms | 7404 KiB |
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 "split.h"
#include <bits/stdc++.h>
using namespace std;
struct node{
vector <int> in,out;
}g[100001];
bool visited[100001];
stack <int> st;
vector <int> scc[100001];
int upto;
void dfs1(int n){
visited[n]=1;
for (auto&i:g[n].out){
if (!visited[i]) dfs1(i);
}
st.push(n);
}
void dfs2(int n){
visited[n]=1;
scc[upto].push_back(n);
for (auto&i:g[n].in){
if (!visited[i]) dfs2(i);
}
}
vector <int> find_split(int n,int a,int b,int c,vector <int> p,vector <int> q){
int m=p.size();
for (int i=0; i<m; i++){
g[p[i]].out.push_back(q[i]);
g[q[i]].out.push_back(p[i]);
g[p[i]].in.push_back(q[i]);
g[q[i]].in.push_back(p[i]);
}
for (int i=0; i<n; i++){
if (!visited[i]) dfs1(i);
}
for (int i=0; i<n; i++) visited[i]=0;
while (!st.empty()){
int t=st.top();
st.pop();
if (!visited[t]){
upto++;
dfs2(t);
}
}
vector <int> mas={};
int sz=0;
for (int i=0; i<upto; i++){
if (scc[i].size()>sz){
sz=scc[i].size();
mas=scc[i];
}
}
vector <int> ans(n,0);
if (b<=c){
if (sz>=b){
for (int i=0; i<b; i++) ans[mas[i]]=2;
bool ff=1;
for (int i=0; i<n; i++){
if (ans[i]) continue;
if (ff){
ans[i]=1;
ff=0;
} else ans[i]=3;
}
}
} else {
if (sz>=c){
for (int i=0; i<c; i++) ans[mas[i]]=3;
bool ff=1;
for (int i=0; i<n; i++){
if (ans[i]) continue;
if (ff){
ans[i]=1;
ff=0;
} else ans[i]=2;
}
}
}
return ans;
}
Compilation message (stderr)
# | 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... |