QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#208430 | #6766. Direction Setting | ucup-team1004 | WA | 0ms | 3744kb | C++14 | 2.3kb | 2023-10-09 16:21:39 | 2023-10-09 16:21:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
const int N=3e2+10,M=3e2+10,INF=1e9;
namespace Flow{
const int V=N,E=M*3*2+N*2*2;
int s,t,kk,head[V],cur[V],vis[V],d[V];
struct edges{
int to,c,w,nex;
}edge[E];
void init(int x,int y){
s=x,t=y,kk=1;
fill(head+s,head+1+t,0);
}
int add(int u,int v,int c,int w){
edge[++kk]={v,c,w,head[u]},head[u]=kk;
edge[++kk]={u,0,-w,head[v]},head[v]=kk;
return kk;
}
bool bfs(){
deque<int>q;
copy(head+s,head+1+t,cur+s);
fill(d+s,d+1+t,INF),d[s]=0;
q.push_back(s);
for(int u;!q.empty();){
u=q.front(),q.pop_front();
for(int i=head[u];i;i=edge[i].nex){
int v=edge[i].to,c=edge[i].c,w=edge[i].w;
if(c&&d[v]>d[u]+w){
d[v]=d[u]+w;
if(w)q.push_back(v);
else q.push_front(v);
}
}
}
return d[t]<INF;
}
int sum;
int dfs(int u,int lim=INF){
if(u==t)return lim;
vis[u]=1;
int flow=0;
for(int i=cur[u];i&&flow<lim;i=edge[i].nex){
cur[u]=i;
int v=edge[i].to,c=edge[i].c;
if(!c||d[v]!=d[u]+edge[i].w||vis[v])continue;
int f=dfs(v,min(lim-flow,edge[i].c));
if(!f)d[v]=INF;
edge[i].c-=f,edge[i^1].c+=f,flow+=f;
sum+=f*edge[i].w;
}
vis[u]=0;
return flow;
}
int dinic(){
int flow=sum=0;
for(;bfs();)flow+=dfs(s);
return flow;
}
}
int T,n,m,s,t,id[M];
void get(){
scanf("%d%d",&n,&m);
Flow::init(s=0,t=n+m+1);
for(int i=1,x;i<=n;i++){
scanf("%d",&x);
Flow::add(i,t,x,0);
Flow::add(i,t,INF,1);
}
for(int i=1,u,v;i<=m;i++){
scanf("%d%d",&u,&v);
Flow::add(s,i+n,1,0);
id[i]=Flow::add(i+n,u,1,0);
Flow::add(i+n,v,1,0);
}
// assert(Flow::dinic()==m);
printf("%d\n",Flow::sum);
for(int i=1;i<=m;i++){
printf("%d",Flow::edge[id[i]].c);
}
puts("");
}
int main(){
for(scanf("%d",&T);T--;)get();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3744kb
input:
2 4 5 0 1 1 5 1 2 1 3 2 3 3 2 4 4 3 2 0 0 2 1 3 3 2
output:
0 00000 0 00
result:
wrong answer [case 1] Participant's actual value is not 0, but 2