QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#563279#8517. Interesting Pathsqwqwf#WA 3ms28872kbC++14885b2024-09-14 09:10:572024-09-14 09:10:57

Judging History

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

  • [2024-09-14 09:10:57]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:28872kb
  • [2024-09-14 09:10:57]
  • 提交

answer

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
//#pragma GCC optimize("Ofast","unroll-loops","inline")
#include<bits/stdc++.h>
#define ll long long
//#define int ll
#define pb push_back
#define pii pair<int,int>
#define MP make_pair
#define fi first
#define se second
using namespace std;
const int N=1e6+10,M=1e6+10,mod=998244353;
int f[N],n,m;
vector<int> e[N];
signed main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1,u,v;i<=m;i++) cin>>u>>v,e[u].pb(v);
	for(int i=1;i<=n;i++) sort(e[i].begin(),e[i].end());
	f[n]=1;
	for(int i=n-1;i>0;i--){
		f[i]=0;
		int mx=0,c=0;
		for(int v:e[i]) if(f[v]) mx=max(mx,f[v]),c++;
		if(!c) f[i]=0;
		else f[i]=mx+c-1;
	}
	cout<<f[1]<<'\n';
	return 0;
}
/*
5 5
1 2
2 3
1 3
2 5
3 5
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

5 3
1 3
2 3
2 5

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

2 0

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

2 1
1 2

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

10 20
2 8
5 8
4 8
3 10
3 7
2 7
2 5
1 7
6 9
6 10
2 4
5 9
2 10
3 9
7 8
4 10
3 6
2 3
5 7
6 8

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: -100
Wrong Answer
time: 3ms
memory: 28872kb

input:

10 30
8 9
1 5
3 6
4 6
4 7
6 9
3 5
5 6
3 8
1 4
3 4
7 8
2 4
4 5
1 8
6 10
2 10
9 10
1 2
8 10
2 7
2 8
2 5
7 9
2 6
4 8
1 7
1 6
7 10
4 9

output:

18

result:

wrong answer 1st numbers differ - expected: '19', found: '18'