QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#570933#9319. Bull FarmniolleRE 1ms6052kbC++142.2kb2024-09-17 19:14:332024-09-17 19:14:33

Judging History

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

  • [2024-09-17 19:14:33]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:6052kb
  • [2024-09-17 19:14:33]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dwn(i,a,b) for(int i=a;i>=b;i--)
#define lowbit(x) (x&(-x))
#define MAXN 2005
#define mp(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-') f=-1; ch=getchar();}
	while('0'<=ch && ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return x*f;
}
int n,m,K,f[MAXN],cnt,vis[MAXN],dis[MAXN][MAXN],d[MAXN];
char str[MAXN<<1];
vector<pair<int,int> > v[MAXN];
vector<int> q[MAXN];
void clr(){
	scanf("%d%d%d",&n,&m,&K);
	rep(i,1,n) f[i] = i;
	rep(i,1,n) v[i].clear();
}
int getf(int x){
	if(x == f[x]) return x;
	return f[x] = getf(f[x]);
}
void ade(int x,int y,int z){
	v[x].push_back(mp(y,z));
}
void merge(int x,int y,int z){
	int fx = getf(x), fy = getf(y);
	if(fx == fy) return;
	f[fy] = fx;
	ade(fx,fy,z); ade(fy,fx,z);
}
int get(char x,char y){
	int u = x - '0', v = y - '0';
	return u * 50 + v;
}
int to[MAXN],bk[MAXN];
void pre(){
	int tmp = 0, flg = 0;
	rep(i,1,m){
		scanf("%s",str);
		rep(j,1,n) to[j] = get(str[2*j-2],str[2*j-1]);
		rep(j,1,n) bk[j] = 0;
		tmp = 0; flg = 0;
		rep(j,1,n){
			bk[to[j]]++;
			if(bk[to[j]] > 1) ++tmp,flg = to[j]; 
		}
		if(tmp > 1) continue;
		if(!tmp){
			rep(j,1,n) merge(j,to[j],i);
		}
		else{
			rep(j,1,n) if(!bk[j]) tmp = j;
			rep(j,1,n) if(to[j] == flg) ade(j,tmp,i);
		}
	}
}
void spfa(int st){
	rep(i,1,n) vis[i] = 0,d[i] = m + 1;
	rep(i,0,m){
//		vector<int> rub;
//		q[i].swap(rub);
		q[i].clear();
	}
	int u,w;
	d[st] = 0; q[0].push_back(st);
	rep(i,0,m){
		for(auto x : q[i]){
			if(vis[x]) continue;
			vis[x] = 1;
			for(auto tmp : v[x]){
				u = tmp.first; w = tmp.second;
				if(vis[u]) continue;
				if(d[u] <= max(w,d[x])) continue;
				d[u] = max(w,d[x]);
				q[d[u]].push_back(u);
			}
		}
	}
	rep(i,1,n) dis[st][i] = d[i];
}
void wk(){
	rep(i,1,n) spfa(i);
	rep(i,1,K){
		scanf("%s",str);
		int a = get(str[0],str[1]),b = get(str[2],str[3]),c = get(str[4],str[5]);
//		cout<<"NOW:"<<a<<" "<<b<<" "<<c<<endl;
		if(dis[a][b] <= c) printf("1");
		else printf("0");
	}
	puts("");
}
int main(){
	int T = read();
	while(T--){
		clr();
		pre();
		wk();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6052kb

input:

2
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401

output:

1011
0100

result:

ok 2 lines

Test #2:

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

input:

1
3 3 6
020202
030301
030201
020102
030203
010201
010303
020303
010202

output:

010101

result:

ok single line: '010101'

Test #3:

score: -100
Runtime Error

input:

200
10 10 5000
01060:04020305080709
0103070:060204050908
09070503080401060:02
050308010204090:0607
03010502040607080:09
03080109020504060:07
06050:09040302080107
07080305010409060:02
030809010:0204060507
0:060908070201050304
060700
090:03
09080:
070405
010703
0:0100
080601
030600
070206
0:0:09
08040...

output:


result: