QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#639675#7738. Equivalent RewritingDu_zkWA 136ms12100kbC++141.9kb2024-10-13 21:26:312024-10-13 21:26:31

Judging History

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

  • [2024-10-13 21:26:31]
  • 评测
  • 测评结果:WA
  • 用时:136ms
  • 内存:12100kb
  • [2024-10-13 21:26:31]
  • 提交

answer

#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;
int n,m;
int k;
int now;
vector<int> a[100005];
int tot[100005];
int f[100005];
int ok;
void solve()
{
	cin>>n>>m;
	int tw=0,o=0,ok=0;
	for(int i=1;i<=m;i++)
	{
		tot[i]=0;
		f[i]=0;
	}
	for(int i=1;i<=n;i++)
		a[i].clear();
	for(int i=1;i<=n;i++)
	{
		cin>>k;
		for(int j=1;j<=k;j++)
		{
			cin>>now;
			a[i].push_back(now);
		}
	}
	for(int i=n;i>=1;i--)
	{
		tw=0;
		for(int j=0;j<a[i].size();j++)
		{
			if(tot[a[i][j]]<2) tw=1;
		}
		if(tw==0)
		{
			int tto=0;
			for(int j=0;j<a[i].size();j++)
				tto=max(tto,f[a[i][j]]);
			cout<<"Yes\n";
			for(int j=1;j<=n-1;j++)
			{
				if(j==i) continue;
				cout<<j<<" ";
				if(j==tto) cout<<i<<" ";
			}
			cout<<n<<"\n";
			ok=1;
			break;
		}
		for(int j=0;j<a[i].size();j++)
		{
			tot[a[i][j]]++;
			f[a[i][j]]=i;
		}
		// cout<<"KKKK:";
		// for(int j=1;j<=m;j++)
		// 	cout<<tot[j]<<" ";
		// cout<<"\n";
	}
	if(ok) return;
	for(int i=1;i<=m;i++)
		tot[i]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<a[i].size();j++)
			tot[a[i][j]]++;
	}
	// cout<<"FKKK:";
	// 	for(int j=1;j<=m;j++)
	// 		cout<<tot[j]<<" ";
	// 	cout<<"\n";
	if(n>1)
	for(int i=1;i<=n;i++)
	{
		o=0;
		for(int j=0;j<a[i].size();j++)
		{
			if(tot[a[i][j]]>1) o=1;
		}
		if(!o){
			cout<<"Yes\n";
			if(i!=n)
			{
				for(int j=1;j<=n;j++)
				{
					if(j==i) continue;
					cout<<j<<" ";
				}
				cout<<i;
				cout<<"\n";
			}
			else{
				cout<<i<<" ";
				for(int j=1;j<n-1;j++)
					cout<<j<<" ";
				cout<<n-1<<endl;
			}
			ok=1;
			break;
		}
	}
	if(ok) return;
	cout<<"No\n";
	return;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}
/*
4
4 3
2 1 2
2 1 3
2 2 3
2 1 2
4 5
1 2
2 1 3
2 3 5
1 4
4 5
1 2
1 4
3 1 3 2
2 3 5
4 4
4 1 2 3 4
4 1 2 3 4
4 1 2 3 4
3 1 2 3 
*/

詳細信息

Test #1:

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

input:

3
3 6
3 3 1 5
2 5 3
2 2 6
2 3
3 1 3 2
2 3 1
1 3
2 2 1

output:

Yes
3 1 2
No
No

result:

ok OK. (3 test cases)

Test #2:

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

input:

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

output:

Yes
1 2 3 4 5 7 6 8 9 10

result:

ok OK. (1 test case)

Test #3:

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

input:

1
20 5
5 4 1 2 5 3
2 5 3
3 5 1 2
5 4 5 1 3 2
3 4 2 5
5 3 1 5 4 2
5 5 1 2 3 4
1 3
4 5 1 2 3
4 4 1 3 5
2 5 2
4 2 3 5 1
3 2 4 5
5 2 3 4 1 5
4 5 2 4 3
1 2
2 4 3
4 4 5 3 1
5 4 1 5 3 2
3 5 1 3

output:

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

result:

ok OK. (1 test case)

Test #4:

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

input:

1
40 10
2 4 1
10 5 8 2 3 6 7 4 1 10 9
3 10 9 7
1 9
10 10 5 6 9 2 8 3 1 4 7
7 8 4 7 5 2 3 6
5 2 6 5 1 10
6 6 5 4 8 7 1
3 4 9 8
9 9 10 4 2 1 8 7 5 3
2 5 7
9 8 6 1 2 9 7 5 10 3
2 8 1
8 8 3 10 9 1 4 5 6
2 3 4
5 5 3 6 2 7
10 3 2 8 9 10 1 7 4 6 5
2 1 9
1 1
3 3 7 4
5 2 6 5 7 1
7 3 2 4 9 10 6 1
1 4
5 6 4 5 ...

output:

Yes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 33 32 34 35 36 37 38 39 40

result:

ok OK. (1 test case)

Test #5:

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

input:

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

output:

Yes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 96 97 95 98 99 100

result:

ok OK. (1 test case)

Test #6:

score: 0
Accepted
time: 2ms
memory: 6072kb

input:

1
5000 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1...

output:

Yes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...

result:

ok OK. (1 test case)

Test #7:

score: 0
Accepted
time: 57ms
memory: 8868kb

input:

1
5000 200
2 121 161
35 27 5 1 189 173 2 37 107 140 172 108 53 163 19 127 102 174 71 178 42 72 74 167 118 120 175 28 75 128 106 190 112 86 171 13
109 110 109 183 17 77 159 188 157 56 14 104 55 179 121 171 64 123 196 140 38 29 134 130 163 108 187 42 68 26 156 138 80 143 182 4 174 67 63 76 79 69 142 3...

output:

Yes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...

result:

ok OK. (1 test case)

Test #8:

score: 0
Accepted
time: 115ms
memory: 11424kb

input:

1
5000 1000
146 147 426 393 758 104 385 277 218 753 477 377 54 465 635 918 97 453 576 270 57 189 230 227 332 345 358 14 178 969 817 840 620 828 837 94 922 844 789 106 250 952 745 212 693 296 677 368 625 150 103 55 266 756 525 60 91 683 364 852 877 792 312 315 997 27 50 866 759 327 557 56 49 947 644 ...

output:

Yes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...

result:

ok OK. (1 test case)

Test #9:

score: 0
Accepted
time: 115ms
memory: 12100kb

input:

1
4999 1000
799 991 88 253 814 577 620 74 338 485 560 435 835 130 279 536 637 188 612 876 634 950 755 534 727 272 657 357 810 113 800 41 439 125 763 311 724 623 976 525 725 869 209 975 888 683 428 4 91 448 936 885 140 233 967 556 369 522 263 483 784 96 808 70 42 391 109 333 778 422 121 862 430 746 6...

output:

Yes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...

result:

ok OK. (1 test case)

Test #10:

score: 0
Accepted
time: 136ms
memory: 11708kb

input:

1
5000 5000
2081 3619 2779 2556 4025 163 2942 2539 4075 189 2823 2189 3571 1168 1474 3383 649 1432 2052 1218 645 1053 1833 2651 3651 1611 1512 1267 3727 4182 2237 4827 3905 3335 3268 1627 2212 3697 2241 884 4015 4902 1504 2223 484 3001 2908 4619 4321 2875 4501 87 2442 3850 2760 834 3985 1807 1880 26...

output:

Yes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...

result:

ok OK. (1 test case)

Test #11:

score: 0
Accepted
time: 135ms
memory: 10564kb

input:

1
1000 5000
2728 456 1809 201 2171 4389 1597 1911 2218 3081 3818 486 3732 263 2483 2923 527 867 782 3405 3803 4039 838 3743 3589 2153 2818 2946 997 11 899 2656 2024 4474 4802 2978 2070 3056 1919 2475 2205 2563 4339 3179 2508 195 3943 3710 4441 3440 3923 4842 3916 4481 912 3076 4866 710 254 4324 1546...

output:

Yes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...

result:

ok OK. (1 test case)

Test #12:

score: -100
Wrong Answer
time: 5ms
memory: 6612kb

input:

1
10 5000
4665 1548 2583 767 790 1820 825 4120 4957 4179 3273 2273 4509 457 3495 667 206 1152 4353 1992 4211 315 4334 905 4043 2826 1094 1708 4132 1046 3359 137 3773 4602 4557 83 605 4257 3514 4430 4968 2253 3041 786 2356 320 1504 1734 4095 1738 2512 3667 140 1487 594 276 3290 4273 4321 87 3343 4451...

output:

No

result:

wrong answer jury found an answer but participant did not (test case 1)