QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#735243#8517. Interesting Pathsucup-team2526WA 0ms3820kbC++201.2kb2024-11-11 18:36:532024-11-11 18:36:53

Judging History

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

  • [2024-11-11 18:36:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3820kb
  • [2024-11-11 18:36:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

#define dbg(x...) \
do { \
std::cout << #x << " -> "; \
err(x); \
} while (0)

void err() {
	std::cout << std::endl;
}

template<class T, class... Ts>
void err(T arg, Ts &... args) {
	std::cout << fixed << setprecision(10) << arg << ' ';
	err(args...);
}

void GENSHEN_START() {
	int n,m;cin >> n >> m;
	vector <int> du(n + 5);
	vector <vector<int>> g(n + 5);
	for (int i = 1;i <= m;i++) {
		int u,v;cin >> u >> v;
		g[u].push_back(v);
		du[v]++;
	}
	vector <int> dis(n + 5,-1);
	dis[1] = 0;
	queue <int> q;
	for (int i = 1;i <= n;i++) {
		if (du[i] == 0 && i != 1) {
			q.push(i);
		}
	}
	while (!q.empty()) {
		auto now = q.front();q.pop();
		for (auto i : g[now]) {
			du[i]--;
			if (du[i] == 0) q.push(i);
		}
	}
	q.push(1);
	while (!q.empty()) {
		auto now = q.front();q.pop();
		for (auto i : g[now]) {
			du[i]--;
			dis[i] = max(dis[i],dis[now] + 1);
			if (du[i] == 0) q.push(i);
		}
	}
	cout << max((int)0,dis[n]);
}

signed main()
{
	ios::sync_with_stdio(false);cin.tie(nullptr);
	int T = 1;
	//cin >> T;
	while (T--) GENSHEN_START();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3560kb

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: 3820kb

input:

2 0

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

2 1
1 2

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

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: 0ms
memory: 3628kb

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:

6

result:

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