QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65707 | #693. Hard Times for Your Data | eyiigjkn | WA | 3ms | 3688kb | C++14 | 1.7kb | 2022-12-03 09:20:37 | 2022-12-03 09:20:40 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll INF=1e18;
int rev[600010],head[1010],nxt[600010],tot=1;
bool visV[1010],visE[600010];
tuple<int,int,int> ans[200010];
mt19937 rnd(0);
struct Edge
{
int v,c,f;
Edge(){}
Edge(int v,int c):v(v),c(c),f(0){}
}edge[600010];
void addedge(int u,int v,int c)
{
nxt[++tot]=head[u];
edge[tot]=Edge(v,c);
head[u]=tot;
}
void addE(int u,int v,int c){addedge(u,v,c);addedge(v,u,0);}
ll dfs(int u,int t,ll minn)
{
if(u==t || !minn) return minn;
visV[u]=1;
ll ans=0;
vector<int> id;
for(int i=head[u];i;i=nxt[i]) id.push_back(i);
shuffle(id.begin(),id.end(),rnd);
for(int i:id)
{
int v=edge[i].v,c=edge[i].c,f=edge[i].f;
if(visV[v] || c-f<=(visE[rev[i]]?1:0)) continue;
visE[i]=1;
ll x=dfs(v,t,min(minn,ll(visE[rev[i]]?(c-f)/2:c-f)));
visE[i]=0;
edge[i].f+=x;edge[i^1].f-=x;
edge[rev[i]].f+=x;edge[rev[i]^1].f-=x;
ans+=x;minn-=x;
if(!minn) break;
}
visV[u]=0;
return ans;
}
int main()
{
int n,m,u,v,c,s,t;
ll sum=0;
cin>>n>>m;s=n+n+1;t=s+1;
for(int i=1;i<=n;i++)
{
scanf("%d",&c);sum+=c;
rev[tot+1]=tot+3;rev[tot+2]=tot+4;
rev[tot+3]=tot+1;rev[tot+4]=tot+2;
addE(s,i,c);addE(i+n,t,c);
}
for(int i=0;i<m;i++)
{
scanf("%d%d%d",&u,&v,&c);
rev[tot+1]=tot+3;rev[tot+2]=tot+4;
rev[tot+3]=tot+1;rev[tot+4]=tot+2;
addE(u,v+n,c);addE(v,u+n,c);
}
sum/=2;
while(sum) sum-=dfs(s,t,INF);
tot=0;
for(int u=1;u<=n;u++)
for(int i=head[u];i;i=nxt[i])
if((v=edge[i].v-n)<u && edge[i].f>0)
ans[++tot]=make_tuple(u,v,edge[i].f);
cout<<tot<<endl;
for(int i=1;i<=tot;i++) printf("%d %d %d\n",get<0>(ans[i]),get<1>(ans[i]),get<2>(ans[i]));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3408kb
input:
5 6 3 1 1 1 2 1 2 1 1 4 1 2 3 2 2 4 1 3 4 1 1 5 3
output:
3 2 1 1 4 3 1 5 1 2
result:
ok OK
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3688kb
input:
10 30 5 6 1 3 5 4 2 5 3 6 1 2 1 1 4 1 1 7 1 1 8 1 1 10 1 2 3 1 2 5 1 2 6 1 2 8 1 2 10 1 4 5 1 4 10 1 5 6 1 5 8 1 5 9 1 6 8 1 6 9 1 7 10 1 8 10 1 9 10 1 6 7 1 3 9 1 4 7 1 7 9 1 3 4 1 3 7 1 8 9 1 3 8 1 6 10 1 3 5 1
output:
20 2 1 1 4 1 1 5 3 1 5 4 1 5 2 1 6 5 1 6 2 1 7 1 1 8 6 1 8 5 1 8 2 1 8 1 1 9 6 1 9 5 1 10 9 1 10 8 1 10 7 1 10 4 1 10 2 1 10 1 1
result:
wrong answer Sum at vertex 1 does not match