QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#735431 | #8517. Interesting Paths | ucup-team2526 | WA | 340ms | 87536kb | C++20 | 1.4kb | 2024-11-11 19:58:54 | 2024-11-11 19:58:55 |
Judging History
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<pair<int,int>>> g(n + 5);
for (int i = 1;i <= m;i++) {
int u,v;cin >> u >> v;
g[u].push_back({v,i});
du[v]++;
}
queue <int> q;
for (int i = 1;i <= n;i++) {
if (du[i] == 0 && i != 1) {
q.push(i);
}
}
vector <int> good(m + 5);
while (!q.empty()) {
auto now = q.front();q.pop();
for (auto [v,p] : g[now]) {
du[v]--;
good[p] = 1;
if (du[v] == 0) q.push(v);
}
}
vector <int> cnt(n + 5);
vector <int> vis(n + 5);
q.push(1);
cnt[1] = 1;
while (!q.empty()) {
auto now = q.front();q.pop();
//dbg(now,cnt[now]);
for (auto [i,p] : g[now]) {
if (good[p]) continue;
du[i]--;
if (!vis[now]) {
cnt[i] += cnt[now];
vis[now] = 1;
}
else {
cnt[i] += 1;
}
if (du[i] == 0) q.push(i);
}
}
cout << max((int)0,cnt[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: 3508kb
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: 3820kb
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: 3788kb
input:
2 0
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
2 1 1 2
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3512kb
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: 0
Accepted
time: 0ms
memory: 3508kb
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:
19
result:
ok 1 number(s): "19"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
20 57 6 20 5 9 8 11 6 17 5 18 14 16 6 18 8 18 1 3 17 20 2 16 4 19 2 15 7 17 17 19 8 16 11 15 13 16 5 20 4 14 5 16 7 12 10 12 3 12 8 13 1 5 6 11 13 17 11 16 2 6 4 5 14 15 3 14 9 13 8 10 18 20 15 17 6 12 5 17 2 10 8 17 15 16 15 20 5 19 10 15 1 2 4 20 4 18 3 16 2 12 8 19 10 19 2 11 12 17 12 20 5 7 1 15
output:
21
result:
ok 1 number(s): "21"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
16 19 5 10 10 13 12 13 15 16 7 11 1 6 14 15 3 4 6 8 11 12 4 5 13 14 5 7 9 12 1 2 2 4 5 12 8 9 1 3
output:
5
result:
ok 1 number(s): "5"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
14 91 3 13 1 9 4 12 1 12 11 14 8 10 9 14 5 11 9 11 1 11 1 2 10 14 1 7 4 9 2 10 13 14 2 6 4 6 12 13 5 13 2 8 1 14 9 10 3 8 2 11 5 14 7 9 6 10 7 11 1 10 12 14 3 14 3 7 7 8 1 13 10 11 2 14 6 14 8 9 6 9 2 4 4 7 4 14 9 13 2 7 6 12 5 7 4 5 2 9 11 12 6 8 8 11 4 8 7 14 7 12 5 12 2 5 11 13 6 7 6 11 7 13 3 4 ...
output:
79
result:
ok 1 number(s): "79"
Test #10:
score: 0
Accepted
time: 8ms
memory: 58148kb
input:
1000000 0
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 0
Accepted
time: 108ms
memory: 35940kb
input:
10000 1000000 3186 5896 193 9783 2762 3101 2793 5391 2587 9231 2991 6139 317 448 361 5290 7372 7580 279 2589 5476 7584 2829 3375 3785 8539 5898 7644 460 2025 2029 6959 1249 8686 1787 5348 840 7031 9515 9862 6122 9224 3911 5359 725 4062 985 5179 3337 4188 6961 8345 5325 6480 8308 9019 7827 9054 759 3...
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 340ms
memory: 87392kb
input:
1000000 1000000 227867 264986 543264 885751 368699 709020 126827 786083 15773 700372 582092 653193 597763 662903 24964 669822 118877 700066 650866 776787 264084 934355 104858 656657 393038 691935 254875 794624 349005 722140 77011 854592 264566 829978 395038 833643 180017 193646 28588 147277 71335 79...
output:
0
result:
ok 1 number(s): "0"
Test #13:
score: -100
Wrong Answer
time: 135ms
memory: 87536kb
input:
1000000 1000000 277718 460482 147752 592243 672428 950124 290176 395254 169855 591213 23051 603108 683561 886805 369178 558263 15523 306646 851733 898093 16252 953612 195928 796663 298711 941197 807239 939884 477390 577792 177636 375148 199307 279986 171470 388424 864738 896318 520095 685892 281955 ...
output:
473761
result:
wrong answer 1st numbers differ - expected: '987489', found: '473761'