QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#595329 | #9424. Stop the Castle 2 | ucup-team5008# | WA | 130ms | 12632kb | C++23 | 4.9kb | 2024-09-28 13:27:23 | 2024-09-28 13:27:24 |
Judging History
answer
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::vector;
#define rep(i,j,k) for(int i=int(j); i<int(k); i++)
#define REP(i,j,k) for(int i=int(j); i<=int(k); i++)
#define per(i,j,k) for(int i=int(j); i>=int(k); i--)
#define ln "\n"
#define all(a) a.begin(),a.end()
#define pb emplace_back
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
//max_flow
template<typename T>
struct max_flow{
struct Edge{
int to;
T cap;
int rev;
};
int N;
vector<vector<Edge>> edge;
vector<int> dist, itr;
max_flow(vii e, vii w){
N = e.size();
edge.resize(N);
rep(i,0,N){
rep(j,0,e[i].size()){
edge[i].pb((Edge){(int)e[i][j],(T)w[i][j],(int)edge[e[i][j]].size()});
edge[e[i][j]].pb((Edge){i,0,(int)edge[i].size()-1});
}
}
}
void bfs(int s){
dist.assign(N,-1);
std::queue<int> que;
dist[s] = 0;
que.push(s);
while(!que.empty()){
int now = que.front(); que.pop();
for(auto p: edge[now]){
int next = p.to;
if(p.cap > 0 && dist[next] < 0){
dist[next] = dist[now]+1;
que.push(next);
}
}
}
}
T dfs(int now, int t, T f){
if(now == t) return f;
for(; itr[now]<edge[now].size(); itr[now]++){
Edge& p = edge[now][itr[now]];
if(p.cap>0 && dist[now]<dist[p.to]){
T mem = dfs(p.to,t,std::min(f,p.cap));
if(mem > 0){
p.cap -= mem;
edge[p.to][p.rev].cap += mem;
return mem;
}
}
}
return 0;
}
T Query(int s, int t){
T ret = 0;
while(true){
bfs(s);
if(dist[t] < 0) break;
itr.assign(N,0);
while(true){
int mem = dfs(s,t,(1ll<<30));
if(mem <= 0) break;
ret += mem;
}
}
return ret;
}
};
void solve(){
ll N,M,K; cin >> N >> M >> K;
std::map<ll,std::map<ll,ll>> r,c;
rep(i,0,N){
ll R,C; cin >> R >> C;
r[R][C] = c[C][R] = i;
}
vi r_o(M, -1), c_o(M, -1);
rep(i,0,M){
ll R,C; cin >> R >> C;
if(r.count(R)){
auto itr = r[R].lower_bound(C);
if(itr != r[R].end() && itr != r[R].begin()){
itr--;
r_o[i] = (*itr).second;
}
}
if(c.count(C)){
auto itr = c[C].lower_bound(R);
if(itr != c[C].end() && itr != c[C].begin()){
itr--;
c_o[i] = (*itr).second;
}
}
}
vii edge(2*N+2), weight(2*N+2);
ll s = 2*N, t = 2*N+1;
rep(i,0,N){
edge[s].pb(i);
weight[s].pb(1);
edge[i+N].pb(t);
weight[i+N].pb(1);
}
std::map<ll,std::map<ll,ll>> mem;
rep(i,0,M){
if(r_o[i] != -1 && c_o[i] != -1){
edge[r_o[i]].pb(c_o[i]+N);
weight[r_o[i]].pb(1);
mem[r_o[i]][c_o[i]+N] = i;
}
}
max_flow<ll> mf(edge,weight);
K = M-K;
ll curr = mf.Query(s,t);
vector<bool> isused(M), iscovered(2*N);
rep(i,0,N){
for(auto p: mf.edge[i]){
if(N <= p.to && p.to < 2*N && p.cap == 0){
isused[mem[i][p.to]] = true;
}
}
}
{
for(auto p: mf.edge[s]){
if(0 <= p.to && p.to < N && p.cap == 0){
iscovered[p.to] = true;
}
}
}
rep(i,N,2*N){
for(auto p: mf.edge[i]){
if(p.to == t && p.cap == 0){
iscovered[i] = true;
}
}
}
rep(i,0,M){
if(curr <= K) break;
if(isused[i]){
isused[i] = false;
curr--;
}
}
rep(i,0,M){
if(curr >= K) break;
if(isused[i]) continue;
if(r_o[i] != -1 && !iscovered[r_o[i]]){
iscovered[r_o[i]] = true;
isused[i] = true;
curr++;
}
else if(c_o[i] != -1 && !iscovered[c_o[i]+N]){
iscovered[c_o[i]+N] = true;
isused[i] = true;
curr++;
}
}
rep(i,0,M){
if(curr >= K) break;
if(!isused[i]){
isused[i] = true;
curr++;
}
}
ll ans = 2*N-r.size()-c.size();
rep(i,0,2*N){
ans -= iscovered[i];
}
cout << ans << ln;
rep(i,0,M){
if(!isused[i]) cout << i+1 << " ";
}
cout << ln;
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
ll T; cin >> T;
while(T--){
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
input:
3 8 6 4 1 3 2 1 2 6 4 1 4 7 6 1 6 3 6 6 2 3 3 1 4 3 4 6 5 2 6 4 3 2 1 10 12 10 10 10 11 1 4 1 5 1 3 2 1 1 2 1 2 2 2 3
output:
4 2 3 5 6 2 2 0 2 3
result:
ok ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 130ms
memory: 12632kb
input:
1224 11 17 14 7 3 4 2 8 13 3 15 3 4 5 11 10 2 3 3 8 6 7 11 2 3 10 4 1 3 12 1 2 5 11 9 11 6 11 10 8 15 1 5 9 14 4 11 1 6 10 7 7 6 11 4 8 4 1 11 18 3 2 14 8 2 14 13 13 9 12 14 12 5 6 8 1 10 5 8 6 8 9 6 6 7 5 12 11 6 11 13 5 1 10 7 6 14 5 6 15 2 4 11 1 1 6 4 14 14 13 9 9 3 10 12 7 5 8 13 9 14 1 9 8 4 9...
output:
7 3 4 5 6 7 8 9 10 11 12 13 15 16 17 15 2 3 0 3 4 5 6 0 2 3 4 5 6 7 8 9 11 1 3 8 1 2 3 0 1 2 3 4 5 6 7 8 9 10 11 12 1 5 6 7 9 10 11 12 8 17 18 19 1 1 2 3 4 5 6 7 8 7 6 8 10 13 14 15 1 10 11 12 13 14 15 16 17 18 19 20 0 1 1 2 3 0 5 6 7 7 8 12 13 14 15 2 10 11 12 13 14 4 3 4 5 6 7 8 ...
result:
wrong answer Participant states the answer to be 23 but is actually 25 (test case 201)