QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187185 | #3855. Regional development | zhylj# | AC ✓ | 4ms | 21964kb | C++14 | 2.3kb | 2023-09-24 15:15:13 | 2023-09-24 15:15:13 |
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)
{
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 19820kb
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:
1 1 1 1 1 1 1 -1 -2 -2 -1 2 2 -2 1 2 1 1 2 -1 -1 1 -1
result:
ok correct plan
Test #2:
score: 0
Accepted
time: 0ms
memory: 19800kb
input:
100 1297 11 27 34 5 7 34 6 7 90 3 80 90 6 37 80 6 37 48 5 47 48 6 47 86 5 56 86 6 56 84 5 63 84 6 38 63 6 66 91 8 12 91 6 12 15 5 15 22 1 22 87 5 46 87 6 46 63 10 63 87 8 71 87 6 65 71 6 38 65 1 38 67 4 29 67 6 9 29 6 9 21 5 16 21 6 16 89 2 89 98 5 4 98 6 4 13 4 13 33 5 14 33 6 14 66 10 66 86 10 57 ...
output:
5 6 -8 6 6 5 6 5 6 5 6 6 8 -5 5 1 -6 6 10 8 6 6 1 4 6 6 5 6 -9 5 -5 4 5 6 -1 10 -5 6 5 7 6 -5 8 5 6 5 5 6 6 -6 -5 5 6 1 6 3 5 6 5 5 6 8 9 6 8 5 6 5 5 6 6 5 6 6 5 6 5 6 6 5 6 -6 10 6 7 5 5 -5 7 5 5 6 6 -6 5 6 6 6 -6 5 -1 -6 5 -5 6 5 5 7 6 6 5 5 8 5 6 -6 5 5 5 -5 -6 6 2 6 5 6 1 5 -5 -6 5 5 6 9 -6 -5 3...
result:
ok correct plan
Test #3:
score: 0
Accepted
time: 0ms
memory: 21964kb
input:
100 1272 18 39 40 14 39 95 4 21 95 14 12 21 14 12 82 16 28 82 14 17 28 14 17 67 5 35 67 14 11 35 1 11 67 15 17 58 4 58 80 4 28 80 14 28 77 3 25 77 10 22 25 14 22 54 4 13 54 14 13 99 4 86 99 14 86 89 16 21 89 14 21 62 4 16 62 14 16 81 4 76 81 14 56 76 1 28 56 14 28 47 4 19 47 14 19 91 4 22 91 14 13 2...
output:
14 4 14 14 -2 14 14 5 14 1 -3 4 4 14 3 10 14 4 14 -14 14 16 14 4 14 4 14 1 14 4 14 4 14 14 4 4 14 14 4 4 13 4 2 14 4 4 14 4 17 14 4 4 14 -9 -4 4 14 14 17 4 4 14 4 4 4 14 -4 4 4 14 14 -14 -16 4 9 4 4 14 -8 4 4 14 -17 14 11 14 4 14 10 4 8 4 14 -8 14 14 4 14 4 14 4 4 14 4 17 1 17 11 7 11 7 7 -7 7 11 11...
result:
ok correct plan
Test #4:
score: 0
Accepted
time: 0ms
memory: 19816kb
input:
100 1350 3 22 75 2 22 50 2 22 35 1 25 35 2 42 76 2 39 42 2 36 39 2 14 36 2 14 33 1 33 72 1 54 72 2 54 73 1 5 73 2 45 92 2 23 92 2 23 26 2 26 62 1 6 62 1 22 86 1 24 86 2 7 24 2 7 55 2 20 39 2 20 73 1 27 73 2 27 68 1 24 68 2 24 98 1 8 98 2 8 33 1 3 33 2 1 3 1 3 97 1 83 97 2 83 90 1 38 90 2 38 86 1 21 ...
output:
2 2 1 2 2 2 2 2 1 1 2 1 -1 2 -1 2 1 1 1 2 2 2 2 1 2 1 2 1 -1 1 2 1 -2 2 -2 2 1 1 2 2 1 1 2 1 1 1 2 1 2 -1 1 2 2 1 2 1 1 -2 2 2 -2 1 -1 1 2 1 2 2 1 1 2 2 -2 2 1 2 1 2 2 2 2 -2 -1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 1 1 2 1 2 1 1 -1 1 1 1 1 -1 2 1 -2 1 2 1 2 2 1 2 1 2 1 2 1 1 2 2 1 2 2 -2 2 2 2 1 -2 1 2 2 2 1...
result:
ok correct plan
Test #5:
score: 0
Accepted
time: 0ms
memory: 19828kb
input:
1000 9780 26 39 260 1 215 260 25 215 483 1 483 801 1 801 977 1 379 977 25 316 379 25 316 732 1 474 732 25 183 474 25 177 183 25 177 788 1 525 788 25 525 909 1 51 909 25 51 565 1 203 565 25 203 353 1 353 655 8 655 814 1 814 999 1 305 999 25 52 305 25 52 978 20 839 978 25 646 839 25 536 646 25 536 571...
output:
1 25 1 1 1 25 25 1 25 25 25 -25 25 1 -1 1 25 1 8 1 1 25 25 -6 25 25 25 1 25 1 25 1 25 1 25 25 1 13 25 1 1 25 25 25 1 1 1 25 1 25 1 1 25 1 25 1 25 25 1 25 1 25 25 1 -25 25 1 25 1 -1 -25 25 25 25 1 1 25 1 25 1 25 1 25 -25 25 1 25 15 25 25 25 1 1 25 25 1 25 1 25 1 1 1 1 25 1 1 1 1 25 1 -1 25 -25 -1 25 ...
result:
ok correct plan
Test #6:
score: 0
Accepted
time: 3ms
memory: 19804kb
input:
20 190 20 2 7 10 4 7 18 4 19 15 1 19 14 1 2 13 1 13 10 3 13 10 1 3 12 8 10 19 10 12 13 12 16 12 8 16 9 3 19 18 2 19 5 2 17 15 4 17 2 4 5 3 1 5 8 14 19 16 4 14 15 19 20 7 13 20 11 3 20 8 7 9 14 9 13 16 13 16 14 1 16 19 1 14 14 8 14 1 3 8 3 3 9 8 9 17 1 17 19 10 1 20 1 10 20 17 4 10 5 4 6 14 6 19 16 1...
output:
10 18 -5 -6 13 10 10 12 19 13 12 9 -2 -15 -5 -18 3 8 16 15 7 11 -12 14 16 14 -1 14 1 3 8 1 10 -19 17 5 14 -4 13 17 4 9 7 13 10 2 8 -13 8 1 5 17 16 2 16 13 -3 15 11 16 17 9 17 14 -5 1 3 3 -6 6 -8 2 -2 -13 19 1 -8 -5 10 10 -1 9 12 12 -10 13 -7 11 -8 16 17 9 6 2 18 -18 -3 14 -2 10 -9 3 15 2 16 -12 5 19...
result:
ok correct plan
Test #7:
score: 0
Accepted
time: 2ms
memory: 19820kb
input:
300 9997 94 3 81 59 80 81 43 40 80 43 40 121 51 121 151 51 95 151 47 95 158 59 149 158 43 149 258 51 99 258 43 99 150 51 150 299 51 29 299 43 29 151 5 151 289 51 13 289 43 13 226 51 182 226 30 182 248 51 6 248 17 6 243 51 91 243 43 91 193 51 169 193 43 169 287 51 237 287 43 153 237 31 153 289 51 155...
output:
59 43 43 51 51 47 59 43 51 43 51 51 -51 5 51 -51 51 30 51 -77 -43 43 51 43 51 43 31 51 43 51 43 43 -43 43 86 51 43 51 43 43 -71 51 43 51 51 43 43 -43 29 51 43 51 43 51 51 43 51 43 51 43 51 43 51 51 51 43 51 43 43 51 51 43 43 51 51 43 43 43 51 51 51 43 51 43 -43 43 43 32 43 43 43 51 35 43 77 51 43 38...
result:
ok correct plan
Test #8:
score: 0
Accepted
time: 4ms
memory: 19816kb
input:
100 4950 497 11 84 473 37 84 457 37 44 399 7 44 434 7 97 276 11 97 299 42 75 227 75 96 345 10 96 6 10 64 345 64 91 15 16 91 390 3 16 431 3 8 449 2 8 129 2 83 360 83 86 430 22 86 377 22 26 354 8 26 30 8 60 386 60 69 473 35 69 181 18 35 161 18 40 246 12 40 100 12 18 224 18 57 312 55 57 253 55 97 417 6...
output:
-24 457 399 434 -221 -198 227 345 -491 345 15 -107 431 449 129 360 430 377 354 30 386 473 181 161 246 100 224 312 253 417 473 418 51 18 317 242 456 214 488 15 432 413 300 318 264 169 211 99 440 477 170 220 90 467 375 126 74 314 63 448 157 201 388 243 479 216 -44 35 392 53 367 -69 278 365 355 149 52 ...
result:
ok correct plan
Test #9:
score: 0
Accepted
time: 0ms
memory: 19848kb
input:
1000 10000 2 403 261 1 423 168 1 977 444 1 298 748 1 77 687 1 229 276 1 791 650 1 39 507 1 747 612 1 882 369 1 376 1000 1 812 953 1 713 123 1 403 749 1 215 394 1 342 218 1 691 673 1 33 289 1 437 652 1 217 223 1 247 665 1 701 192 1 229 726 1 18 850 1 585 343 1 407 925 1 940 382 1 920 851 1 901 740 1 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 -...
result:
ok correct plan
Test #10:
score: 0
Accepted
time: 0ms
memory: 19816kb
input:
1000 1935 4 860 820 1 102 103 1 910 911 1 230 190 1 234 235 3 151 150 1 506 507 1 528 568 1 273 313 1 149 150 1 798 758 1 597 557 1 610 650 1 746 747 1 63 23 3 102 142 3 619 620 1 81 41 3 238 278 1 760 759 1 799 798 1 853 852 1 193 194 3 199 239 1 150 190 1 876 916 1 996 997 2 244 243 1 282 242 1 27...
output:
1 1 1 -3 3 1 1 1 -3 1 1 1 -3 1 -1 -1 -3 -1 1 -3 -3 1 3 1 1 1 2 1 -3 -3 1 1 1 1 -3 1 1 1 1 1 1 1 -3 1 -3 -3 -3 3 1 -1 1 1 3 1 -3 1 1 3 3 1 3 1 -1 1 1 1 1 1 1 3 1 1 1 3 1 3 -1 -1 1 1 1 1 3 1 1 -1 3 1 1 -1 1 -1 1 -1 3 1 1 1 -3 -3 1 3 1 3 -1 1 1 -1 -1 1 -1 1 3 1 1 3 2 1 1 3 1 1 -1 -1 1 -1 3 1 1 1 1 1 1 ...
result:
ok correct plan