QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#507907#7157. Bikes vs CarsCrysfly0 123ms12180kbC++172.0kb2024-08-06 23:18:162024-08-06 23:18:16

Judging History

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

  • [2024-08-06 23:18:16]
  • 评测
  • 测评结果:0
  • 用时:123ms
  • 内存:12180kb
  • [2024-08-06 23:18:16]
  • 提交

answer

// what is matter? never mind. 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 500006
#define inf 0x3f3f3f3f

int n,up;
int a[505][505],b[505][505];

struct edge{
	int u,v,w;
};

int fa[maxn];
int gf(int x){
	while(x!=fa[x])x=fa[x]=fa[fa[x]];
	return x;
}

vector<edge> mst(vector<edge>es){
	For(i,1,n) fa[i]=i;
	sort(es.begin(),es.end(),[&](auto a,auto b){
		return a.w>b.w;
	});
	vector<edge>res;
	for(auto [u,v,w]:es){
		if(gf(u)!=gf(v)){
			fa[gf(u)]=gf(v);
			res.pb({u,v,w});
		}
	}
	return res;
}

signed main()
{
	n=read(),up=read();
	For(i,1,n)For(j,1,i-1)a[i][j]=a[j][i]=read();
	For(i,1,n)For(j,1,i-1)b[i][j]=b[j][i]=read();
	For(i,1,n)For(j,i+1,n)
		For(k,1,n)if(k!=i&&k!=j){
			if(min(a[i][k],a[k][j])>a[i][j]){
				puts("NO");
				exit(0);
			}
			if(min(b[i][k],b[k][j])>b[i][j]){
				puts("NO");
				exit(0);
			}
		}
	
	vector<edge>es,resa,resb;
	For(i,1,n)For(j,i+1,n) if(a[i][j]+b[i][j]>=up) es.pb({i,j,a[i][j]});
	resa=mst(es);
	es.clear();
	For(i,1,n)For(j,i+1,n) if(a[i][j]+b[i][j]>=up) es.pb({i,j,b[i][j]});
	resb=mst(es);
	cout<<resa.size()+resb.size()<<"\n";
	for(auto [u,v,w]:resa) cout<<u-1<<" "<<v-1<<" "<<up-w<<"\n";
	for(auto [u,v,w]:resb) cout<<u-1<<" "<<v-1<<" "<<w<<"\n";
	return 0;
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 0ms
memory: 7700kb

input:

14 1000000
494185
494185 494185
494185 494185 494185
494185 494185 494185 494185
494185 494185 494185 494185 494185
494185 494185 494185 494185 494185 494185
494185 494185 494185 494185 494185 494185 494185
494185 494185 494185 494185 494185 494185 494185 494185
494185 494185 494185 494185 494185 49...

output:

26
5 7 505815
6 11 505815
6 10 505815
6 9 505815
6 8 505815
6 7 505815
5 13 505815
5 12 505815
4 13 505815
3 13 505815
0 12 505815
1 11 505815
1 2 505815
5 7 536641
6 11 536641
6 10 536641
6 9 536641
6 8 536641
6 7 536641
5 13 536641
5 12 536641
4 13 536641
3 13 536641
0 12 536641
1 11 536641
1 2 53...

result:

ok 

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 7704kb

input:

37 1000000
891050
891050 891050
891050 891050 891050
891050 891050 891050 891050
891050 891050 891050 891050 891050
891050 891050 891050 891050 891050 891050
891050 891050 891050 891050 891050 891050 891050
891050 891050 891050 891050 891050 891050 891050 891050
891050 891050 891050 891050 891050 89...

output:

0

result:

wrong answer The graph is not connected

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #16:

score: 17
Accepted
time: 1ms
memory: 7636kb

input:

14 1000000
494185
494185 494185
494185 494185 494185
494185 494185 494185 494185
494185 494185 494185 494185 494185
494185 494185 494185 494185 494185 494185
494185 494185 494185 494185 494185 494185 494185
494185 494185 494185 494185 494185 494185 494185 494185
494185 494185 494185 494185 494185 49...

output:

26
5 7 505815
6 11 505815
6 10 505815
6 9 505815
6 8 505815
6 7 505815
5 13 505815
5 12 505815
4 13 505815
3 13 505815
0 12 505815
1 11 505815
1 2 505815
5 7 536641
6 11 536641
6 10 536641
6 9 536641
6 8 536641
6 7 536641
5 13 536641
5 12 536641
4 13 536641
3 13 536641
0 12 536641
1 11 536641
1 2 53...

result:

ok 

Test #17:

score: 0
Wrong Answer
time: 1ms
memory: 7908kb

input:

37 1000000
891050
891050 891050
891050 891050 891050
891050 891050 891050 891050
891050 891050 891050 891050 891050
891050 891050 891050 891050 891050 891050
891050 891050 891050 891050 891050 891050 891050
891050 891050 891050 891050 891050 891050 891050 891050
891050 891050 891050 891050 891050 89...

output:

0

result:

wrong answer The graph is not connected

Subtask #4:

score: 0
Wrong Answer

Test #39:

score: 18
Accepted
time: 4ms
memory: 8200kb

input:

163 1
0
0 0
0 1 0
1 0 0 0
0 0 0 0 0
1 0 0 0 1 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0 1
0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 1
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 1
0 1 0 1 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 1 1 0 0 0
0 0 0 0 0 1 0 0 0 0 0 1 1 0 0
0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 1 0 0 ...

output:

324
56 70 0
55 116 0
55 126 0
55 128 0
55 143 0
55 146 0
55 157 0
55 159 0
55 161 0
56 62 0
56 65 0
56 66 0
55 108 0
56 74 0
56 79 0
56 83 0
56 97 0
56 98 0
56 110 0
56 113 0
56 114 0
56 123 0
56 125 0
54 117 0
54 87 0
54 88 0
54 90 0
54 91 0
54 99 0
54 100 0
54 103 0
54 104 0
54 105 0
54 109 0
56 1...

result:

ok 

Test #40:

score: 18
Accepted
time: 0ms
memory: 8948kb

input:

387 1
0
0 0
0 0 0
1 1 1 0
1 0 0 1 0
1 1 0 0 1 1
1 1 1 1 0 0 0
1 0 0 0 0 1 1 0
1 1 0 0 1 1 0 0 0
1 0 1 0 1 1 1 1 1 0
1 0 0 0 0 0 1 1 1 1 0
0 0 0 1 1 0 1 0 1 1 0 1
0 1 0 1 1 0 1 1 0 0 1 0 0
1 1 1 1 1 0 1 0 0 1 1 1 0 1
0 0 0 0 0 1 1 1 0 1 1 1 0 0 1
1 1 0 0 0 1 1 1 1 1 1 0 0 1 0 0
1 1 0 0 0 1 0 1 1 1 0 ...

output:

NO

result:

ok 

Test #41:

score: 18
Accepted
time: 110ms
memory: 11088kb

input:

482 1
0
0 0
0 0 0
0 0 0 0
0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 ...

output:

962
37 100 0
303 439 0
37 181 0
190 271 0
37 173 0
37 159 0
303 470 0
190 242 0
304 332 0
110 427 0
304 344 0
304 345 0
304 348 0
190 272 0
37 84 0
304 373 0
110 452 0
190 195 0
37 62 0
304 381 0
37 51 0
304 385 0
189 471 0
36 478 0
36 467 0
189 434 0
190 321 0
37 384 0
302 479 0
110 255 0
303 325 0...

result:

ok 

Test #42:

score: 18
Accepted
time: 3ms
memory: 7736kb

input:

475 1
0
1 1
0 0 0
0 0 1 0
0 1 0 0 0
0 0 1 1 0 1
1 0 0 0 1 1 0
0 0 1 0 0 1 1 0
1 1 1 1 0 1 1 0 1
0 0 0 1 0 0 0 1 0 1
1 0 1 1 0 1 1 1 1 0 0
1 0 0 0 1 1 1 0 1 0 1 0
0 0 0 0 1 1 1 0 1 1 1 1 0
0 1 1 1 0 1 0 1 1 1 0 0 0 1
0 1 0 1 1 0 1 0 1 1 1 0 1 1 0
0 0 0 0 0 1 0 0 1 1 1 1 0 0 1 0
1 0 1 0 1 1 0 1 0 0 1 ...

output:

NO

result:

ok 

Test #43:

score: 18
Accepted
time: 119ms
memory: 8908kb

input:

500 1
0
0 0
0 0 0
0 0 0 0
0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 ...

output:

998
58 107 0
181 217 0
22 484 0
58 189 0
22 496 0
181 227 0
93 139 0
223 350 0
181 252 0
23 63 0
223 338 0
58 137 0
23 102 0
58 128 0
223 314 0
355 456 0
93 218 0
354 478 0
23 157 0
181 359 0
278 495 0
93 232 0
127 287 0
57 488 0
354 453 0
354 451 0
279 286 0
279 299 0
57 449 0
92 395 0
180 380 0
58...

result:

ok 

Test #44:

score: 18
Accepted
time: 2ms
memory: 7748kb

input:

500 1
0
0 0
0 0 1
1 1 0 0
1 1 1 1 0
0 0 0 0 1 1
0 1 0 1 1 0 1
1 1 1 1 1 1 1 1
0 1 0 0 1 0 1 0 1
0 1 0 1 0 0 0 0 0 0
1 0 1 0 0 0 0 0 0 1 1
0 0 1 0 0 0 0 1 0 1 0 1
0 1 1 0 1 0 0 0 0 0 1 1 0
1 1 0 1 0 1 0 1 0 1 1 1 0 1
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
1 1 1 0 1 1 1 0 0 1 0 0 0 0 0 1
0 0 0 0 1 0 1 0 0 0 0 ...

output:

NO

result:

ok 

Test #45:

score: 18
Accepted
time: 123ms
memory: 9564kb

input:

500 1
0
0 0
0 0 0
0 0 0 1
0 0 0 1 1
0 0 0 0 0 0
1 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 ...

output:

998
197 360 0
196 485 0
197 202 0
197 204 0
197 211 0
197 213 0
197 238 0
197 274 0
197 290 0
197 305 0
197 308 0
197 316 0
197 330 0
196 473 0
197 366 0
197 375 0
197 439 0
197 457 0
197 460 0
197 481 0
197 484 0
197 486 0
198 206 0
198 212 0
198 225 0
196 377 0
196 255 0
196 269 0
196 271 0
196 30...

result:

ok 

Test #46:

score: 18
Accepted
time: 117ms
memory: 8104kb

input:

500 1
1
0 0
0 0 1
0 0 0 0
0 0 0 0 1
0 0 0 0 0 0
0 0 0 0 0 0 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 ...

output:

998
204 205 0
214 215 0
392 393 0
212 213 0
210 211 0
394 395 0
208 209 0
206 207 0
396 397 0
216 217 0
202 203 0
398 399 0
200 201 0
198 199 0
400 401 0
196 197 0
194 195 0
402 403 0
228 229 0
238 239 0
380 381 0
236 237 0
234 235 0
382 383 0
232 233 0
230 231 0
384 385 0
192 193 0
226 227 0
386 38...

result:

ok 

Test #47:

score: 18
Accepted
time: 0ms
memory: 7620kb

input:

6 1
1
0 0
0 0 0
0 0 0 0
0 0 0 0 1
0
0 1
0 0 0
0 0 0 1
1 0 0 0 0

output:

10
0 1 0
4 5 0
0 5 1
1 2 1
3 4 1
0 5 1
1 2 1
3 4 1
0 1 0
4 5 0

result:

ok 

Test #48:

score: 0
Wrong Answer
time: 123ms
memory: 12180kb

input:

500 1
0
0 1
0 1 1
0 1 1 1
0 1 1 1 1
0 1 1 1 1 1
0 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 1 1 1 1 1 1 0 0
1 0 0 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 1 0 1
1 0 0 0 0 0 0 0 1 0 1 1
1 0 0 0 0 0 0 0 1 0 1 1 1
1 0 0 0 0 0 0 0 1 0 1 1 1 1
1 0 0 0 0 0 0 0 1 0 1 1 1 1 1
0 1 1 1 1 1 1 0 0 1 0 0 0 0 0 0
0 1 1 1 1 1 1 0 0 1 0 ...

output:

996
202 260 0
202 236 0
202 239 0
202 240 0
202 241 0
202 242 0
202 244 0
202 245 0
202 246 0
202 249 0
202 250 0
202 252 0
202 253 0
202 258 0
202 259 0
202 235 0
202 262 0
202 264 0
202 265 0
202 266 0
202 269 0
202 271 0
202 273 0
202 274 0
202 276 0
202 278 0
202 282 0
202 284 0
202 286 0
202 20...

result:

wrong answer The graph is not connected

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%