QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#556577#7706. Rikka with Linkership2077#WA 966ms5276kbC++23998b2024-09-10 19:29:202024-09-10 19:29:21

Judging History

This is the latest submission verdict.

  • [2024-09-10 19:29:21]
  • Judged
  • Verdict: WA
  • Time: 966ms
  • Memory: 5276kb
  • [2024-09-10 19:29:20]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=(1<<18)+5;
int n,m,e[18],res[M],cyc[M];
int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
	return x;
}
void solve(){
	n=read();m=read();
	for (int i=0;i<n;i++) e[i]=0;
	for (int i=0;i<m;i++){
		int x=read()-1,y=read()-1;
		e[x]|=1<<y;
	} int ans=n;
	for (int sta=0;sta<1<<n;sta++) res[sta]=0;
	for (int i=n-1;i;i--){ cyc[0]=e[i];
		for (int sta=1;sta<1<<i;sta++) cyc[sta]=0;
		for (int sta=0;sta<1<<i;sta++)
			for (int j=0;j<i;j++) if (~sta>>j&1&&cyc[sta]>>j&1)
				cyc[sta^1<<j]|=e[j];
		for (int sta=0;sta<1<<i;sta++)
			if (cyc[sta]>>i&1) res[sta]=1;
	}
	for (int sta=1;sta<1<<n;sta++)
		for (int i=0;i<n;i++)
			if (sta>>i&1)
				res[sta]|=res[sta^1<<i];
	for (int sta=0;sta<1<<n;sta++)
		if (!res[sta]) ans=min(ans,n-__builtin_popcount(sta));
	printf("%d\n",ans+n);
}
int main(){int T=read();while (T--) solve(); return 0;}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 2
1 2
2 3
3 3
1 2
2 3
3 1
5 7
1 2
2 3
3 5
5 4
4 2
2 5
3 1

output:

3
4
6

result:

ok 3 number(s): "3 4 6"

Test #2:

score: -100
Wrong Answer
time: 966ms
memory: 5276kb

input:

1000
18 93
1 6
1 13
2 1
2 8
3 6
4 8
5 4
5 6
5 9
5 10
5 11
5 12
5 13
5 18
6 2
6 4
6 16
7 1
7 2
7 3
7 9
7 10
7 13
7 15
8 6
8 9
9 5
9 8
9 10
9 13
9 14
10 1
10 3
10 4
10 5
10 6
10 8
10 11
10 13
11 1
11 2
11 3
11 4
11 6
11 7
11 9
11 12
11 14
11 15
12 1
12 2
12 4
12 6
12 10
12 13
12 14
12 16
12 17
12 18
1...

output:

25
29
28
28
29
31
29
31
32
33
30
32
32
29
32
33
33
33
32
34
20
19
20
22
21
13
22
20
20
19
22
15
21
16
20
23
19
21
22
17
22
22
20
17
23
20
20
19
20
22
22
22
21
13
15
16
22
20
20
20
22
21
20
21
23
19
22
22
23
17
20
17
20
22
20
22
18
16
23
21
20
21
22
23
21
22
21
20
21
14
21
20
17
23
19
21
22
21
21
21
...

result:

wrong answer 1st numbers differ - expected: '23', found: '25'