QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#486469 | #1359. Setting Maps | yqh2025 | WA | 2ms | 8324kb | C++14 | 2.4kb | 2024-07-21 20:25:45 | 2024-07-21 20:25:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9;
namespace maxflow{
const int NS=1e5+10,inf=1e9,MS=1e6+10;
int s,t;
struct as{
int v,w;
}e[MS];
int k=-1;
vector<int>f[NS];
int now[NS],dep[NS];
bool bfs(){
memset(now,0,sizeof(now));
memset(dep,0,sizeof(dep));
queue<int>q;q.push(s);dep[s]=1;
while(!q.empty()){
int u=q.front();q.pop();
for(int i=0,fs=f[u].size();i<fs;i++){
int v=e[f[u][i]].v,w=e[f[u][i]].w;
if(w&&!dep[v]){
dep[v]=dep[u]+1;
if(v==t)return 1;
q.push(v);
}
}
}
return 0;
}
int dfs(int u,int sum){
if(u==t)return sum;
int x,fl=0;
for(int i=now[u],fs=f[u].size();i<fs&∑i++){
now[u]=i;
int v=e[f[u][i]].v,w=e[f[u][i]].w;
if(dep[v]==dep[u]+1&&w){
x=dfs(v,min(sum,w));
if(!x)dep[v]=0;
e[f[u][i]].w-=x;e[f[u][i]^1].w+=x;
fl+=x,sum-=x;
}
}
return fl;
}
void add(int x,int y,int z){
// cout<<x<<" "<<y<<" "<<z<<endl;
e[++k]=(as){y,z};f[x].push_back(k);
e[++k]=(as){x,0};f[y].push_back(k);
}
int ZDL(int ss,int tt){
s=ss,t=tt;int ans=0;
while(bfs())ans+=dfs(s,inf);
return ans;
}
void init(){
for(int i=0;i<=k;i++)e[i].w=e[i].v=0;
k=-1;s=t=0;
for(int i=0;i<NS;i++)f[i].clear();
memset(dep,0,sizeof(dep)),memset(now,0,sizeof(now));
}
}
const int N=1e5+10;
int n,m,k,c[N];
int s,t;
int main(){
scanf("%d%d%d",&n,&m,&k);
scanf("%d%d",&s,&t);
int sum=0;
for(int i=1;i<=n;i++){
scanf("%d",&c[i]);sum+=c[i];
int x=i*2,y=i*2+1;
for(int j=1;j<=k;j++){
maxflow::add((x-1)*k+j,(y-1)*k+j,c[i]);
if(j<k){
maxflow::add((x-1)*k+j,(y-1)*k+j+1,inf);
// maxflow::add((x-1)*k+j,(x-1)*k+j+1,inf);
if(i==n)maxflow::add((y-1)*k+j,(y-1)*k+j+1,inf);
}
}
}
for(int i=1;i<=m;i++){
int u,v;scanf("%d%d",&u,&v);
int x=u*2+1,y=v*2;
for(int j=1;j<=k;j++){
maxflow::add((x-1)*k+j,(y-1)*k+j,inf);
}
}
s=(s*2-1)*k+1,t=k*(t*2)+k;
// cout<<s<<" "<<t<<endl;
int ans=maxflow::ZDL(s,t);
// cout<<ans<<endl;
if(ans>sum){
cout<<-1;return 0;
}
maxflow::bfs();
vector<int>ve;
for(int i=1;i<=n;i++){
int x=i*2,y=i*2+1;
for(int j=1;j<=k;j++){
if(maxflow::dep[(x-1)*k+j]&&!maxflow::dep[(y-1)*k+j]){
// cout<<i<<" "<<j<<endl;
ve.push_back(i);
// break;
}
}
}
cout<<ve.size()<<endl;
for(int i:ve)cout<<i<<" ";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 6932kb
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: 2ms
memory: 8184kb
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: 0ms
memory: 8324kb
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: 0ms
memory: 7344kb
input:
2 2 2 2 1 100 200 1 2 2 1
output:
2 1 2
result:
ok answer = 300
Test #5:
score: 0
Accepted
time: 0ms
memory: 7888kb
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: -100
Wrong Answer
time: 0ms
memory: 7736kb
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:
74 1 2 3 4 5 6 7 8 10 11 12 14 16 17 18 19 21 23 24 25 26 28 29 30 32 33 34 35 37 38 39 40 43 44 45 46 48 49 50 51 52 55 56 57 58 59 61 62 63 64 66 67 68 70 71 73 74 75 76 78 79 80 82 83 84 86 87 88 90 91 93 94 95 96
result:
wrong answer Given vertex set from user output does not cover k vertices in some path