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>
#define pii pair<int, int>
#define pib pair<int, bool>
#define mp make_pair
using namespace std;
set<int> adj[2505];
vector<int> ans;
int N;
pii id[5];
int cnt[5];
int dist[2505];
bool found;
void BFS(int a, int b) {
queue<pii> q;
q.push(mp(b, id[2].second));
q.push(mp(a, id[1].second));
memset(dist, 0, sizeof(dist));
cnt[1] = 0, cnt[2] = 0, cnt[3] = 0;
int u, lol;
while(!q.empty()) {
u = q.front().first;
lol = q.front().second;
q.pop();
if(cnt[lol] == id[lol].first) continue;
for(int v : adj[u]) {
if(dist[v] == 0 && cnt[lol] < id[lol].first) {
cnt[lol]++;
dist[v] = lol;
q.push(mp(v, lol));
}
}
}
if(cnt[id[1].second] >= id[1].first && cnt[id[2].second] >= id[2].first) {
for(int i = 0; i < N; i++) {
ans[i] = dist[i] == 0 ? id[3].second : dist[i];
}
found = 1;
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
N = n, id[1].first = a, id[2].first = b, id[3].first = c;
id[1].second = 1, id[2].second = 2, id[3].second = 3;
sort(id + 1, id + 4);
ans.resize(N);
for(int i = 0; i < N; i++) {
adj[p[i]].insert(q[i]);
adj[q[i]].insert(p[i]);
}
for(int i = 0; i < N; i++) {
adj[p[i]].erase(q[i]);
adj[q[i]].erase(p[i]);
BFS(p[i], q[i]);
if(found) return ans;
BFS(q[i], p[i]);
if(found) return ans;
adj[p[i]].insert(q[i]);
adj[q[i]].insert(p[i]);
}
cout << "-1\n";
return ans;
}
# | 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... |