QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#282269 | #1359. Setting Maps | zhicheng | RE | 3ms | 7868kb | C++14 | 2.1kb | 2023-12-11 17:18:27 | 2023-12-11 17:18:28 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1010,M=200010;
int n,tot=1,minu,maxu,vis[N],cur[N],lev[N],src,des,first[N],nnext[M],to[M];
ll w[M],ww[M];
queue<int>q;
vector<int>anss;
void add(int x,int y,ll z){
nnext[++tot]=first[x];
first[x]=tot;
to[tot]=y;
w[tot]=z;
}
bool bfs(){
int u;
while(!q.empty()){
q.pop();
}
for(int i=minu;i<=maxu;i++){
cur[i]=first[i];
lev[i]=-1;
}
lev[src]=0;
q.push(src);
while(!q.empty()){
u=q.front();
q.pop();
for(int e=first[u];e;e=nnext[e]){
if(w[e]&&lev[to[e]]==-1){
lev[to[e]]=lev[u]+1;
q.push(to[e]);
if(to[e]==des){
return 1;
}
}
}
}
return 0;
}
ll dinic(int u,ll flow){
ll res=0,delta;
if(u==des){
return flow;
}
if(u%(n*2)==des%(n*2)&&flow){
printf("-1");
exit(0);
}
for(int &e=cur[u];e;e=nnext[e]){
if(w[e]&&lev[to[e]]>lev[u]){
delta=dinic(to[e],min(flow-res,w[e]));
if(delta){
w[e]-=delta;
w[e^1]+=delta;
res+=delta;
if(flow==res){
break;
}
}
}
}
if(flow!=res){
lev[u]=-1;
}
return res;
}
void dfs(int u){
vis[u]=1;
for(int e=first[u];e;e=nnext[e]){
if(!vis[to[e]]&&w[e]>0){
dfs(to[e]);
}
}
}
int main(){
int m,k,a,b,pp=0;
ll ans=0;
scanf("%d%d%d%d%d",&n,&m,&k,&src,&des);
minu=1;
maxu=n*2*k;
des+=(k-1)*n*2+n;
for(int i=1;i<=n;i++){
scanf("%d",&a);
for(int j=1;j<=k;j++){
add((j-1)*2*n+i,(j-1)*2*n+i+n,a);
add((j-1)*2*n+i+n,(j-1)*2*n+i,0);
}
}
while(m--){
scanf("%d%d",&a,&b);
for(int i=1;i<=k;i++){
add((i-1)*2*n+a+n,(i-1)*2*n+b,1e18);
add((i-1)*2*n+b,(i-1)*2*n+a+n,0);
}
}
for(int i=1;i<=k-1;i++){
for(int j=1;j<=n;j++){
add((i-1)*2*n+j,i*2*n+j+n,1e18);
add(i*2*n+j+n,(i-1)*2*n+j,0);
}
}
while(bfs()){
ans+=dinic(src,1e18);
pp=1;
}
if(!pp||ans==1e18){
printf("-1");
return 0;
}
dfs(src);
for(int i=1;i<=n*2*k;i++){
for(int e=first[i];e;e=nnext[e]){
if(vis[i]&&!vis[to[e]]&&to[e]==i+n&&w[e]==0){
anss.push_back(i%(n*2));
}
}
}
printf("%d\n",anss.size());
for(auto i:anss){
printf("%d ",i);
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7840kb
input:
3 2 5 1 3 1 60 35 1 2 2 3
output:
-1
result:
ok answer = IMPOSSIBLE
Test #2:
score: 0
Accepted
time: 1ms
memory: 5804kb
input:
7 11 1 1 7 100 5 7 16 11 12 100 1 2 1 3 1 4 1 5 2 3 2 6 3 6 4 3 4 7 5 7 6 7
output:
4 2 3 4 5
result:
ok answer = 39
Test #3:
score: 0
Accepted
time: 3ms
memory: 5764kb
input:
11 17 2 1 11 1000 10 10 10 10 10 10 10 10 10 1000 1 2 1 3 1 4 1 5 1 6 2 7 3 7 4 7 5 8 6 8 7 8 7 9 7 10 8 9 8 11 9 11 10 11
output:
6 5 6 7 8 9 10
result:
ok answer = 60
Test #4:
score: 0
Accepted
time: 1ms
memory: 7856kb
input:
2 2 2 2 1 100 200 1 2 2 1
output:
2 2 1
result:
ok answer = 300
Test #5:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
5 5 5 1 5 1 1 1 1 1 1 2 2 3 3 4 4 5 1 5
output:
-1
result:
ok answer = IMPOSSIBLE
Test #6:
score: 0
Accepted
time: 0ms
memory: 5768kb
input:
100 120 5 1 5 5367720 2854323 1799056 9744604 3215334 7580413 6269402 3208439 8812449 3297484 2047196 4044341 7514502 2928715 9335004 3935096 6660663 3356480 4801491 5786147 895995 6710240 222342 4469390 1543213 6678041 8838445 6741919 8138951 5273670 8983795 5131484 4245746 7460466 8357966 8464419 ...
output:
-1
result:
ok answer = IMPOSSIBLE
Test #7:
score: 0
Accepted
time: 1ms
memory: 5696kb
input:
2 1 5 1 2 10 10 1 2
output:
-1
result:
ok answer = IMPOSSIBLE
Test #8:
score: 0
Accepted
time: 1ms
memory: 5844kb
input:
154 304 2 67 7 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 100000...
output:
2 67 7
result:
ok answer = 20000000
Test #9:
score: 0
Accepted
time: 0ms
memory: 7868kb
input:
75 146 1 15 2 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 1000000...
output:
1 15
result:
ok answer = 10000000
Test #10:
score: -100
Runtime Error
input:
182 360 4 97 110 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 1000...