# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1075596 | mindiyak | Split the Attractions (IOI19_split) | C++14 | 39 ms | 8828 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 <vector>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
vector<vector<int>> paths(1e5+5);
int len = 0,pos = 0;
void dfs(int k,int m,int length){
if(length > len){
pos = k;
length = len;
}
for(int l:paths[k]){
if(l==m)continue;
dfs(l,k,length+1);
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
int sub1 = 1;
for(int i=0;i<p.size();i++){
paths[p[i]].push_back(q[i]);
paths[q[i]].push_back(p[i]);
}
for(int i=0;i<n;i++)if(paths[i].size() > 2)sub1 = 0;
vector<int> temp = {a,b,c};
sort(temp.begin(),temp.end());
a = temp[0];b = temp[1];c = temp[2];
if(a == 1){
queue<int> pq;
pq.push(0);
vector<int> ans(n,0);
while(b > 0){
int node = pq.front();pq.pop();
if(ans[node] == 0){
ans[node] = 2;
b--;
for(int l:paths[node]){
pq.push(l);
}
}
}
for(int i=0;i<n;i++){
if(ans[i] == 0){
ans[i] = 1;
break;
}
}
for(int i=0;i<n;i++){
if(ans[i] == 0){
ans[i] = 3;
}
}
return ans;
}
if(sub1 == 1){
dfs(0,-1,1);
queue<int> pq;
pq.push(pos);
vector<int> ans(n,0);
while(a > 0){
int k = pq.front();pq.pop();
if(ans[k] != 0)continue;
ans[k] = 1;
a--;
for(int l:paths[k]){
pq.push(l);
}
}
while(b > 0){
int k = pq.front();pq.pop();
if(ans[k] != 0)continue;
ans[k] = 2;
b--;
for(int l:paths[k]){
pq.push(l);
}
}
for(int i=0;i<n;i++){
if(ans[i] == 0){
ans[i] = 3;
}
}
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... |