QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#208431#6766. Direction Settingucup-team1004RE 1ms3912kbC++142.3kb2023-10-09 16:22:022023-10-09 16:22:02

Judging History

你现在查看的是最新测评结果

  • [2023-10-09 16:22:02]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3912kb
  • [2023-10-09 16:22:02]
  • 提交

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);
	}
	Flow::dinic();
	// 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;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3824kb

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:

2
00100
0
01

result:

ok 2 cases

Test #2:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

120
21 14
0 1 2 2 3 2 0 1 0 3 3 2 1 1 2 0 1 3 1 0 0
6 12
14 11
10 18
15 12
6 11
15 8
3 4
10 11
3 18
5 13
5 19
5 10
17 18
4 2
20 21
9 3 0 4 7 9 5 2 0 4 0 1 6 1 5 8 3 2 7 0
16 6
12 6
11 4
6 6
19 10
17 19
20 20
1 17
15 10
3 2
5 16
7 8
6 1
6 4
18 16
1 8
4 1
20 6
6 9
4 15
7 5
6 16
12 8 0 9 5 8
4 5
6 3
2 ...

output:

0
00000000000000
1
000000000000000000100
0
0100001000001000
2
001000111000001001000001
2
00001000001
2
000000001000100000000011
3
0000010001010001010010
0
00
0
0000000000000000000
0
0000000000000010
2
0000110001000
3
000100000
0
0000000
0
000000000000000
0
0000000000000000000
2
00000001100000000000
...

result:

ok 120 cases

Test #3:

score: 0
Accepted
time: 1ms
memory: 3868kb

input:

120
5 9
1 2 2 3 1
2 2
2 4
1 5
4 3
3 4
3 3
1 5
5 4
4 3
5 4
1 0 1 1 1
2 3
5 3
1 4
4 3
15 17
0 1 1 3 1 2 1 1 1 1 1 2 0 1 1
14 6
13 12
11 4
9 8
9 4
10 5
10 2
4 4
7 4
11 10
15 6
7 1
5 3
13 14
15 12
2 14
11 6
13 17
2 2 1 1 2 1 0 0 1 4 1 1 1
5 11
6 2
2 1
5 2
1 12
7 10
10 2
1 3
3 11
7 1
9 7
11 10
11 2
4 3
7...

output:

0
011100000
0
0111
0
00001010011100010
0
11010000001001001
0
0000100
5
0000011000101
4
1000000
2
000000101010011011001
0
00000
0
0001
0
00000
0
1001
5
00110101100001100
4
000100101
4
00100101
4
10000000101010000
0
110000001010100
0
010000101000001
0
0001001111010100000
4
00000000100
2
00000001001110...

result:

ok 120 cases

Test #4:

score: 0
Accepted
time: 1ms
memory: 3912kb

input:

120
12 11
7 0 0 1 0 0 1 1 0 0 1 0
12 1
1 9
1 2
1 8
3 1
6 1
10 1
1 7
5 1
11 1
4 1
11 10
1 0 0 0 1 0 7 0 0 0 1
7 11
6 7
7 5
8 7
10 7
9 7
7 4
7 1
7 2
3 7
24 23
1 1 1 1 0 5 1 1 1 1 0 1 1 1 1 0 1 0 1 1 1 1 0 1
20 6
12 6
6 9
1 6
6 15
14 6
6 2
6 18
23 6
10 6
3 6
6 16
6 7
17 6
6 13
19 6
6 22
5 6
4 6
6 11
6 ...

output:

0
01100000011
0
0000001010
0
11010101011101010011001
0
1010
0
0001101111101
0
1000110001101101011
0
10100101
0
00011011110
0
101001111011011001110110
0
1001111110010001
0
00100
0
0010101001
0
00101101011111101
0
100001110100100000
0
10011100001110011000
0
010010000101000111001
0
010
0
001100110
0
10...

result:

ok 120 cases

Test #5:

score: -100
Runtime Error

input:

10
300 300
0 0 0 1 6 3 0 36 0 0 0 0 8 53 23 2 8 7 8 4 1 0 3 5 0 4 0 0 2 5 5 5 7 0 0 4 3 0 0 21 2 7 6 2 0 0 0 4 0 67 3 4 9 3 1 1 0 6 2 2 0 0 0 0 0 41 5 0 0 15 2 5 0 6 5 4 0 7 4 4 6 8 0 7 2 6 0 4 4 0 8 22 1 2 6 3 0 3 6 0 0 3 0 0 6 3 0 63 3 7 7 4 0 0 0 26 0 0 1 3 6 1 1 0 0 22 0 2 0 0 1 7 4 1 0 1 0 4 0 ...

output:


result: