QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#518244 | #2760. Simurgh | Dimash | 0 | 2ms | 9196kb | C++20 | 4.2kb | 2024-08-13 18:44:24 | 2024-08-13 18:44:24 |
answer
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 512 * 512,M = 512;
int dat[N],dep[N],vis[N],m,w[N],p[N],pos[N];
bool in[N];
vector<int> tr;
vector<pair<int,int>>g[N];
void dfs(int v) {
vis[v] = 1;
for(auto [to,i]:g[v]) {
if(vis[to]) continue;
dep[to] = dep[v] + 1;
tr.push_back(i);in[i] = 1;
w[to] = i;p[to] = v;
dfs(to);
}
}
vector<int> upd(int i,int j) {
vector<int> f = tr;
f.erase(f.begin() + pos[i]);
f.push_back(j);
return f;
}
int P[N];
int get(int v) {
if(P[v] == v) return v;
return P[v] = get(P[v]);
}
bool merge(int a,int b) {
a = get(a);
b = get(b);
if(a == b) return false;
P[a] = b;
return true;
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
m = (int)v.size();
for(int i = 0;i < (int)u.size();i++) {
g[u[i]].push_back({v[i],i});
g[v[i]].push_back({u[i],i});
}
dfs(0);
for(int i = 0;i < n - 1;i++) {
pos[tr[i]] = i;
}
memset(dat,-1,sizeof(dat));
int ct = count_common_roads(tr);
for(int i = 0;i < m;i++) {
if(in[i]) continue;
if(dep[u[i]] > dep[v[i]]) {
swap(u[i],v[i]);
}
int x = v[i];
vector<int> t;
while(x != u[i]) {
t.push_back(w[x]);
x = p[x];
}
sort(t.begin(),t.end(),[&](int x,int y) {
return dat[x] < dat[y];
});
if(dat[t[0]] != -1) continue;
int tp = -1;
if(dat[t.back()] == -1) {
vector<int> bf;
for(int j:t) {
vector<int> f = upd(j,i);
int c = count_common_roads(f);
if(c == ct + 1) {
tp = 1;
dat[j] = 0;
} else if(c == ct - 1) {
tp = 0;
dat[j] = 1;
} else {
bf.push_back(j);
}
}
if(tp == -1) {
tp = 0;
}
for(int j:bf) {
dat[j] = tp;
}
} else {
int c = count_common_roads(upd(t.back(),i));
if(c == ct) {
tp = dat[t.back()];
} else if(c == ct - 1) {
tp = 0;
} else {
tp = 1;
}
for(int j:t) {
if(dat[j] != -1) continue;
c = count_common_roads(upd(j,i));
if(c == ct) {
dat[j] = tp;
} else if(c == ct - 1) {
dat[j] = 1;
} else {
dat[j] = 0;
}
}
}
}
int left = (n - 1) - ct;
for(int i = 0;i < n && left;i++) {
int it = 0;
auto check = [&](int l,int r)->bool {
iota(P,P+n,0);
vector<int> A;
for(int j = l;j <= r;j++) {
merge(i,g[i][j].first);
A.push_back(g[i][j].second);
}
int _ = 0;
for(int k:tr) {
if(merge(u[k],v[k])) {
_ += dat[k];
A.push_back(k);
}
}
_ = count_common_roads(A) - _;
return (_ > 0);
};
for(int j = (int)g[i].size() - 1;j >= 0;--j) {
if(in[g[i][j].second]) {
g[i].erase(g[i].begin() + j);
}
}
// cout << i << ' ' << (int)g[i].size() << '\n';
while(it < (int)g[i].size()) {
int l = it - 1,r = (int)g[i].size();
while(r - l > 1) {
int mid = (l + r) >> 1;
if(check(it,mid)) {
r = mid;
} else {
l = mid;
}
}
if(r == (int)g[i].size()) break;
dat[g[i][r].second] = 1;
it = r + 1;
}
}
tr.clear();
for(int i = 0;i < m;++i) {
if(dat[i] == 1) {
tr.push_back(i);
}
}
return tr;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 13
Accepted
time: 0ms
memory: 9196kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 7 21 30000 2 0 0 1 5 2 2 6 1 3 3 0 6 0 4 5 3 2 4 0 1 4 0 5 4 3 4 6 6 1 2 1 5 3 2 4 5 6 5 1 6 3 7 10 9 13 12 17
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 7 9 10 12 13 17
result:
ok correct
Test #2:
score: 13
Accepted
time: 2ms
memory: 6832kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 7 21 30000 4 6 1 6 2 3 0 3 2 1 2 6 5 6 6 3 0 2 1 0 4 2 1 3 5 2 5 0 0 6 5 3 4 5 5 1 3 4 1 4 4 0 4 16 10 0 20 18
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 0 4 10 16 18 20
result:
ok correct
Test #3:
score: 13
Accepted
time: 2ms
memory: 8944kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 7 21 30000 2 5 0 4 4 5 4 3 5 3 1 3 3 6 4 1 6 0 5 6 6 2 6 1 6 4 3 2 2 1 1 0 0 2 5 0 5 1 4 2 0 3 20 17 15 9 2 19
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 2 9 15 17 19 20
result:
ok correct
Test #4:
score: 13
Accepted
time: 1ms
memory: 6876kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 7 13 30000 2 4 4 3 3 2 0 3 0 4 6 3 6 1 4 5 6 2 1 3 5 6 6 0 6 4 3 9 12 7 0 4
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 0 3 4 7 9 12
result:
ok correct
Test #5:
score: 13
Accepted
time: 0ms
memory: 9168kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 6 10 30000 5 2 0 1 1 2 0 3 3 2 1 4 0 5 3 5 4 3 1 3 5 0 7 2 1
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 0 1 2 5 7
result:
ok correct
Test #6:
score: 13
Accepted
time: 1ms
memory: 8940kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 7 16 30000 3 4 2 5 2 1 0 5 1 5 0 2 2 6 6 1 4 6 0 1 2 3 6 3 3 1 1 4 4 5 3 5 0 9 5 15 3 11
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs OK 0 3 5 9 11 15
result:
ok correct
Test #7:
score: 0
Wrong Answer
time: 1ms
memory: 8872kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 2 1 30000 0 1 0
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs WA NO
result:
wrong answer WA in grader: NO
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #58:
score: 0
Wrong Answer
time: 0ms
memory: 9160kb
input:
wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd 2 1 12000 1 0 0
output:
lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs WA NO
result:
wrong answer WA in grader: NO
Subtask #5:
score: 0
Skipped
Dependency #1:
0%