QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#187184 | #3855. Regional development | zhylj# | WA | 0ms | 19816kb | C++14 | 2.3kb | 2023-09-24 15:14:50 | 2023-09-24 15:14:50 |
Judging History
answer
#include<bits/stdc++.h>
#define int ll
#define mp make_pair
#define qr read()
#define nc getchar
#define in(x) x=read()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read()
{
char ch=' ';
int f=1,x=0;
for(;!isdigit(ch);ch=nc())if(ch=='-')f*=-1;
for(;isdigit(ch);ch=nc())x=x*10+ch-'0';
return f*x;
}
#define N 1000000
struct edge
{
int v,nxt;
ll f;
}e[2*N];
int ecnt=1,head[N],cur[N];
void add(int u,int v,int f)
{
cout<<u<<"->"<<v<<":"<<f<<'\n';
e[++ecnt]={v,head[u],f};head[u]=ecnt;
e[++ecnt]={u,head[v],0ll};head[v]=ecnt;
}
int n,S,T;
int q[N],tag[N],he=0,ta=1;
bool bfs()
{
for(int i=1;i<=T;i++)tag[i]=0;
he=0,ta=1;q[0]=S;
tag[S]=1;
while(he<ta)
{
int x=q[he++];
for(int o=head[x];o;o=e[o].nxt)
{
if(e[o].f&&!tag[e[o].v])
{
tag[e[o].v]=tag[x]+1,q[ta++]=e[o].v;
}
}
}
return !!tag[T];
}
ll dfs(int x,ll flow)
{
if(x==T)return flow;
ll used=0;
for(int &o=cur[x];o;o=e[o].nxt)
{
if(e[o].f&&tag[x]<tag[e[o].v])
{
ll ret=dfs(e[o].v,min(flow-used,e[o].f));
if(ret)
{
e[o].f-=ret;e[o^1].f+=ret;
used+=ret;
if(used==flow)return flow;
}
}
}
return used;
}
ll dinic()
{
ll ans=0;
while(bfs())
{
for(int i=1;i<=T;i++)cur[i]=head[i];
ans+=dfs(S,1e16);
}
return ans;
}
int x[1000010],y[1000010],z[1000010],id[1000010],deg[1000010];
signed main()
{
int n=qr,m=qr,b=qr;
for(int i=1;i<=m;i++)
{
in(x[i]),in(y[i]),in(z[i]);
deg[y[i]]+=z[i];
deg[x[i]]-=z[i];
}
S=n+1,T=n+2;
int sum1=0,sum2=0;
for(int i=1;i<=n;i++)
{
if(deg[i]>0)add(i,T,deg[i]/b),sum1+=deg[i]/b;
if(deg[i]<0)add(S,i,-deg[i]/b),sum2-=deg[i]/b;
}
for(int i=1;i<=m;i++)
{
id[i]=ecnt+1;
add(x[i],y[i],1);
}
if(sum1!=sum2)return puts("IMPOSSIBLE"),0;
int ans=dinic();
if(ans!=sum1)return puts("IMPOSSIBLE"),0;
for(int i=1;i<=m;i++)
{
if(e[id[i]].f==0)cout<<z[i]-b<<'\n';
else cout<<z[i]<<'\n';
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 19816kb
input:
10 23 3 2 10 1 2 6 1 6 9 1 7 9 1 6 7 1 3 6 1 1 3 1 1 6 2 6 10 1 2 9 1 4 9 2 4 7 2 3 10 2 3 9 1 6 8 1 7 8 2 3 5 1 5 9 1 8 9 2 3 8 2 1 5 2 1 4 1 5 10 2
output:
11->1:2 11->2:1 11->3:2 11->4:1 8->12:1 9->12:3 10->12:2 2->10:1 2->6:1 6->9:1 7->9:1 6->7:1 3->6:1 1->3:1 1->6:1 6->10:1 2->9:1 4->9:1 4->7:1 3->10:1 3->9:1 6->8:1 7->8:1 3->5:1 5->9:1 8->9:1 3->8:1 1->5:1 1->4:1 5->10:1 1 1 1 1 1 1 1 -1 -2 -2 -1 2 2 -2 1 2 1 1 2 -1 -1 1 -1
result:
wrong output format Expected integer, but "11->1:2" found