Task: | Going Dutch |
Sender: | KnowYourArchitecture |
Submission time: | 2017-10-24 18:56:07 +0300 |
Language: | C++ |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.03 s | details |
#2 | WRONG ANSWER | 0.04 s | details |
#3 | WRONG ANSWER | 0.04 s | details |
#4 | WRONG ANSWER | 0.04 s | details |
#5 | WRONG ANSWER | 0.04 s | details |
#6 | WRONG ANSWER | 0.04 s | details |
#7 | WRONG ANSWER | 0.05 s | details |
#8 | WRONG ANSWER | 0.04 s | details |
#9 | WRONG ANSWER | 0.04 s | details |
#10 | WRONG ANSWER | 0.03 s | details |
#11 | WRONG ANSWER | 0.04 s | details |
#12 | WRONG ANSWER | 0.03 s | details |
#13 | WRONG ANSWER | 0.04 s | details |
#14 | WRONG ANSWER | 0.05 s | details |
#15 | WRONG ANSWER | 0.05 s | details |
#16 | ACCEPTED | 0.05 s | details |
#17 | ACCEPTED | 0.04 s | details |
#18 | WRONG ANSWER | 0.04 s | details |
#19 | WRONG ANSWER | 0.04 s | details |
#20 | ACCEPTED | 0.04 s | details |
#21 | ACCEPTED | 0.04 s | details |
#22 | WRONG ANSWER | 0.04 s | details |
#23 | WRONG ANSWER | 0.04 s | details |
#24 | WRONG ANSWER | 0.05 s | details |
#25 | WRONG ANSWER | 0.06 s | details |
#26 | WRONG ANSWER | 0.04 s | details |
#27 | WRONG ANSWER | 0.03 s | details |
#28 | WRONG ANSWER | 0.04 s | details |
#29 | WRONG ANSWER | 0.05 s | details |
#30 | WRONG ANSWER | 0.06 s | details |
#31 | WRONG ANSWER | 0.06 s | details |
#32 | WRONG ANSWER | 0.03 s | details |
#33 | WRONG ANSWER | 0.04 s | details |
#34 | WRONG ANSWER | 0.03 s | details |
#35 | WRONG ANSWER | 0.05 s | details |
#36 | WRONG ANSWER | 0.04 s | details |
#37 | WRONG ANSWER | 0.04 s | details |
#38 | WRONG ANSWER | 0.04 s | details |
#39 | WRONG ANSWER | 0.03 s | details |
#40 | WRONG ANSWER | 0.04 s | details |
#41 | WRONG ANSWER | 0.03 s | details |
#42 | WRONG ANSWER | 0.04 s | details |
#43 | ACCEPTED | 0.04 s | details |
Code
#include <bits/stdc++.h> #define F first #define S second using namespace std; typedef long long ll; const ll inf=1e18; template<int V,int E> struct MinCostFlow{ struct Edge{int a,b;ll ca,co;} es[E*2]; int eu=0,nmz=0; vector<int> g[V+1]; ll p[V+1],d[V+1]; int fr[V+1],u[V+1]; void addEdge(int a,int b, ll ca, ll co){ nmz=0; es[eu++]={a,b,ca,co}; es[eu++]={b,a,0,-co}; g[a].push_back(eu-2); g[b].push_back(eu-1); } void normalize(int source){ if(nmz)return;nmz=1; for(int i=1;i<=V;i++)p[i]=inf,u[i]=0; p[source]=0; queue<int> q;q.push(source); while(!q.empty()){ int x=q.front();u[x]=0;q.pop(); for(int e:g[x]){ if(es[e].ca>0&&p[x]+es[e].co<p[es[e].b]){ p[es[e].b]=p[x]+es[e].co; if(!u[es[e].b]){ u[es[e].b]=1; q.push(es[e].b); } } } } } ll augment(int x, ll fl){ if(fr[x]==-1)return fl; ll r=augment(es[fr[x]].a,min(fl,es[fr[x]].ca)); es[fr[x]].ca-=r; es[fr[x]^1].ca+=r; return r; } pair<ll,ll> flow(int source, int sink, ll mf){ priority_queue<pair<ll,int>> dij; for(int i=1;i<=V;i++){ u[i]=0;fr[i]=-1;d[i]=inf; } d[source]=0; dij.push({0,source}); while(!dij.empty()){ auto x=dij.top();dij.pop(); if(u[x.S])continue; u[x.S]=1; for(int e:g[x.S]){ ll nd=d[x.S]+es[e].co+p[x.S]-p[es[e].b]; if(es[e].ca>0&&nd<d[es[e].b]){ d[es[e].b]=nd; fr[es[e].b]=e; dij.push({-nd,es[e].b}); } } } ll co = d[sink]+p[sink]; for(int i=1;i<=V;i++){ if(fr[i]!=-1)p[i]+=d[i]; } if(u[sink]){ ll fl=augment(sink,mf); return {fl,fl*co}; } else return {0,0}; } pair<ll,ll> getKFlow(int source,int sink,ll k){ ll fl=0;ll co=0; normalize(source); while(1){ pair<ll,ll> t = flow(source,sink,k); fl+=t.F;k-=t.F;co+=t.S; if(k==0||t.F==0)break; } return {fl,co}; } }; int main(){ int M,N; cin>>M>>N; vector<ll> cc(M); for(int i=0;i<N;++i){ int a,b,c; cin>>a>>b>>c; cc[a]-=c; cc[b]+=c; } vector<ll> neg; vector<ll> pos; for(int i=0;i<M;++i){ if(cc[i]<0)neg.push_back(i); else if(cc[i]>0)pos.push_back(i); } MinCostFlow<20*3+2,(20*3+2)*(20*3+2)> f; for(auto it : neg){ f.addEdge(1,it+3,-cc[it],0); for(auto jt : pos){ f.addEdge(it+3,jt+3,inf,1); } } for(auto it : pos){ f.addEdge(it+3,2,cc[it],0); } auto r = f.getKFlow(1,2,inf); cout<<r.S<<endl; }
Test details
Test 1
Verdict: WRONG ANSWER
input |
---|
20 144 0 1 1000 0 1 1000 0 1 1000 0 1 1000 ... |
correct output |
---|
16 |
user output |
---|
71716 |
Test 2
Verdict: WRONG ANSWER
input |
---|
20 121 1 0 578 0 2 1000 0 2 1000 0 2 1000 ... |
correct output |
---|
17 |
user output |
---|
59623 |
Test 3
Verdict: WRONG ANSWER
input |
---|
20 144 0 1 1000 0 1 1000 0 1 883 0 2 1000 ... |
correct output |
---|
17 |
user output |
---|
70274 |
Test 4
Verdict: WRONG ANSWER
input |
---|
20 119 1 0 1000 1 0 1000 1 0 1000 1 0 1000 ... |
correct output |
---|
16 |
user output |
---|
57834 |
Test 5
Verdict: WRONG ANSWER
input |
---|
20 167 0 1 1000 0 1 219 0 2 1000 0 2 1000 ... |
correct output |
---|
16 |
user output |
---|
82593 |
Test 6
Verdict: WRONG ANSWER
input |
---|
20 116 1 0 1000 1 0 1000 1 0 1000 1 0 1000 ... |
correct output |
---|
16 |
user output |
---|
54711 |
Test 7
Verdict: WRONG ANSWER
input |
---|
20 160 1 0 1000 1 0 1000 1 0 1000 1 0 1000 ... |
correct output |
---|
16 |
user output |
---|
79190 |
Test 8
Verdict: WRONG ANSWER
input |
---|
20 123 0 1 1000 0 1 1000 0 1 1000 0 1 1000 ... |
correct output |
---|
16 |
user output |
---|
57992 |
Test 9
Verdict: WRONG ANSWER
input |
---|
20 170 0 1 1000 0 1 1000 0 1 1000 0 1 1000 ... |
correct output |
---|
16 |
user output |
---|
84121 |
Test 10
Verdict: WRONG ANSWER
input |
---|
20 210 1 0 1000 1 0 1000 1 0 1000 1 0 1000 ... |
correct output |
---|
15 |
user output |
---|
105737 |
Test 11
Verdict: WRONG ANSWER
input |
---|
20 100 1 0 1000 1 0 1000 1 0 420 0 2 1000 ... |
correct output |
---|
15 |
user output |
---|
50895 |
Test 12
Verdict: WRONG ANSWER
input |
---|
20 123 1 0 1000 1 0 1000 1 0 1000 1 0 1000 ... |
correct output |
---|
15 |
user output |
---|
59642 |
Test 13
Verdict: WRONG ANSWER
input |
---|
20 138 1 0 1000 1 0 1000 1 0 1000 1 0 1000 ... |
correct output |
---|
14 |
user output |
---|
64619 |
Test 14
Verdict: WRONG ANSWER
input |
---|
20 132 1 0 1000 1 0 1000 1 0 1000 1 0 1000 ... |
correct output |
---|
15 |
user output |
---|
66306 |
Test 15
Verdict: WRONG ANSWER
input |
---|
20 141 0 1 1000 0 1 1000 0 1 1000 0 1 1000 ... |
correct output |
---|
15 |
user output |
---|
66922 |
Test 16
Verdict: ACCEPTED
input |
---|
20 380 0 1 20 0 2 20 0 3 20 0 4 20 ... |
correct output |
---|
0 |
user output |
---|
0 |
Test 17
Verdict: ACCEPTED
input |
---|
20 0 |
correct output |
---|
0 |
user output |
---|
0 |
Test 18
Verdict: WRONG ANSWER
input |
---|
3 1000 0 1 1000 0 1 1000 0 1 1000 0 1 1000 ... |
correct output |
---|
1 |
user output |
---|
1000000 |
Test 19
Verdict: WRONG ANSWER
input |
---|
13 12 1 0 1 2 0 1 3 0 10 4 0 10 ... |
correct output |
---|
9 |
user output |
---|
1222 |
Test 20
Verdict: ACCEPTED
input |
---|
20 1 0 1 1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 21
Verdict: ACCEPTED
input |
---|
20 10 0 1 1 2 3 1 4 5 1 6 7 1 ... |
correct output |
---|
10 |
user output |
---|
10 |
Test 22
Verdict: WRONG ANSWER
input |
---|
6 49 0 4 3 3 0 1 5 0 10 1 0 1 ... |
correct output |
---|
5 |
user output |
---|
14 |
Test 23
Verdict: WRONG ANSWER
input |
---|
9 50 8 7 4 8 2 7 0 4 2 4 5 1 ... |
correct output |
---|
5 |
user output |
---|
24 |
Test 24
Verdict: WRONG ANSWER
input |
---|
20 296 6 11 22 15 11 1 9 4 1 8 6 4 ... |
correct output |
---|
16 |
user output |
---|
2134 |
Test 25
Verdict: WRONG ANSWER
input |
---|
20 999 18 17 1 8 15 1 15 6 3 1 19 5 ... |
correct output |
---|
12 |
user output |
---|
77 |
Test 26
Verdict: WRONG ANSWER
input |
---|
20 997 1 0 1 0 19 14 13 3 8 6 13 8 ... |
correct output |
---|
10 |
user output |
---|
34 |
Test 27
Verdict: WRONG ANSWER
input |
---|
5 10 4 3 2 0 1 4 3 4 7 3 0 1 ... |
correct output |
---|
3 |
user output |
---|
40 |
Test 28
Verdict: WRONG ANSWER
input |
---|
20 26 12 13 7 19 16 2 15 14 2 4 3 1 ... |
correct output |
---|
8 |
user output |
---|
37 |
Test 29
Verdict: WRONG ANSWER
input |
---|
9 6 0 1 2 0 2 1 3 4 2 3 5 1 ... |
correct output |
---|
6 |
user output |
---|
9 |
Test 30
Verdict: WRONG ANSWER
input |
---|
18 16 0 1 1 0 2 1 3 4 1 3 5 1 ... |
correct output |
---|
12 |
user output |
---|
4008 |
Test 31
Verdict: WRONG ANSWER
input |
---|
20 14 0 1 1 0 2 1 3 4 1 3 5 1 ... |
correct output |
---|
11 |
user output |
---|
20 |
Test 32
Verdict: WRONG ANSWER
input |
---|
20 11 0 1 2 3 2 1 5 4 1 6 8 2 ... |
correct output |
---|
11 |
user output |
---|
18 |
Test 33
Verdict: WRONG ANSWER
input |
---|
20 11 0 1 2 3 2 1 5 4 1 6 8 4 ... |
correct output |
---|
11 |
user output |
---|
32 |
Test 34
Verdict: WRONG ANSWER
input |
---|
9 6 4 8 6 4 5 2 2 6 5 3 7 5 ... |
correct output |
---|
6 |
user output |
---|
20 |
Test 35
Verdict: WRONG ANSWER
input |
---|
9 8 0 1 23 0 2 20 3 4 4 5 2 2 ... |
correct output |
---|
7 |
user output |
---|
53 |
Test 36
Verdict: WRONG ANSWER
input |
---|
15 13 1 0 1 2 0 1 3 5 5 4 5 5 ... |
correct output |
---|
12 |
user output |
---|
530 |
Test 37
Verdict: WRONG ANSWER
input |
---|
15 13 0 2 1000 1 2 1000 3 4 800 3 5 400 ... |
correct output |
---|
12 |
user output |
---|
4000 |
Test 38
Verdict: WRONG ANSWER
input |
---|
18 16 0 2 1 1 2 1 3 7 10 4 7 10 ... |
correct output |
---|
15 |
user output |
---|
2444 |
Test 39
Verdict: WRONG ANSWER
input |
---|
20 18 0 1 1 0 2 1 0 3 1 4 5 5 ... |
correct output |
---|
16 |
user output |
---|
2343 |
Test 40
Verdict: WRONG ANSWER
input |
---|
20 42 0 1 1000 0 1 1000 0 1 1000 0 1 1000 ... |
correct output |
---|
16 |
user output |
---|
30465 |
Test 41
Verdict: WRONG ANSWER
input |
---|
20 18 0 1 1000 0 1 1000 0 1 1000 0 1 1000 ... |
correct output |
---|
6 |
user output |
---|
15015 |
Test 42
Verdict: WRONG ANSWER
input |
---|
20 15 1 0 1 3 0 1 5 2 1 6 2 1 ... |
correct output |
---|
13 |
user output |
---|
15 |
Test 43
Verdict: ACCEPTED
input |
---|
20 2 3 8 1 15 7 1 |
correct output |
---|
2 |
user output |
---|
2 |