QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282272 | #1359. Setting Maps | zhicheng | RE | 1ms | 8252kb | C++14 | 2.3kb | 2023-12-11 17:29:47 | 2023-12-11 17:29:48 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1010,M=200010;
int k,dess,viss[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>v[N];
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;
}
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]);
}
}
}
void dfss(int u,int now){
if(u==dess&&now<k){
printf("-1");
exit(0);
}
viss[u]=1;
for(auto i:v[u]){
if(!viss[i]){
dfss(i,now+1);
}
}
viss[u]=0;
}
int main(){
int n,m,a,b;
ll ans=0;
scanf("%d%d%d%d%d",&n,&m,&k,&src,&des);
minu=1;
maxu=n*2*k;
dess=des;
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);
v[a].push_back(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);
}
}
dfss(src,1);
while(bfs()){
ans+=dinic(src,1e18);
}
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);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8192kb
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: 8252kb
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: 1ms
memory: 6200kb
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: 6196kb
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: 5904kb
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: 1ms
memory: 5964kb
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: 5916kb
input:
2 1 5 1 2 10 10 1 2
output:
-1
result:
ok answer = IMPOSSIBLE
Test #8:
score: 0
Accepted
time: 1ms
memory: 5928kb
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: 1ms
memory: 5904kb
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...