QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#753138 | #8517. Interesting Paths | 2022dyx | WA | 9ms | 54380kb | C++14 | 926b | 2024-11-16 11:29:19 | 2024-11-16 11:29:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m, dp[N];
long long ans = 1;
bool vis[N][2], ok;
vector <int> e[N][2];
void dfs1(int x) {
vis[x][0] = true;
if (!ok) dp[x] = true;
if (x == n) ok = true;
for (int i : e[x][0]) if (!vis[i][0]) dfs1(i);
if (!ok) dp[x] = false;
}
void dfs2(int x) {
vis[x][1] = true;
for (int i : e[x][1]) if (!vis[i][1]) dfs2(i);
}
int main() {
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> m;
for (int i = 1, x, y; i <= m; ++i) {
cin >> x >> y;
e[x][0].push_back(y);
e[y][1].push_back(x);
}
dfs1(1);
dfs2(n);
if (!ok) {
cout << 0;
return 0;
}
for (int i = 1; i <= n; ++i) {
if (!vis[i][0] || !vis[i][1] || dp[i]) continue;
for (int j : e[i][1]) if (vis[j][0] && vis[j][1]) dp[i] += dp[j];
int tmp = 0;
for (int j : e[i][0]) if (dp[j]) ++tmp;
ans += 1LL * dp[i] * tmp;
}
cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 53480kb
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: 8ms
memory: 54264kb
input:
5 3 1 3 2 3 2 5
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 9ms
memory: 53196kb
input:
2 0
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 3ms
memory: 53768kb
input:
2 1 1 2
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 4ms
memory: 52864kb
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: 4ms
memory: 54380kb
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:
34
result:
wrong answer 1st numbers differ - expected: '19', found: '34'