Task: | Bicikli |
Sender: | henrikaalto |
Submission time: | 2019-07-24 15:28:00 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 100 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.01 s | details |
#4 | ACCEPTED | 0.01 s | details |
#5 | ACCEPTED | 0.01 s | details |
#6 | ACCEPTED | 0.02 s | details |
#7 | ACCEPTED | 0.01 s | details |
#8 | ACCEPTED | 0.06 s | details |
#9 | ACCEPTED | 0.07 s | details |
#10 | ACCEPTED | 0.06 s | details |
Code
#include <bits/stdc++.h> using namespace std; #define MAXN 10100 vector<int> v[MAXN], rev[MAXN], loops; int p[MAXN], reachable[MAXN]; void create_topo(int s) { if (p[s] == 1) { loops.push_back(s); return; } if (p[s] == 2) return; p[s] = 1; for (int u : v[s]) { create_topo(u); } p[s] = 2; } void reverse_trav(int s) { if (reachable[s]) return; reachable[s] = 1; for (int u : rev[s]) { reverse_trav(u); } } const long mod = (long) 1e11; int pad = 0; int visited[MAXN]; long res[MAXN]; long calc(int s) { if (s == 0) return 1; if (visited[s]) return res[s]; visited[s] = 1; long o = 0; for (int u : rev[s]) { o += calc(u); if (o >= mod) pad = 1; o %= mod; } return res[s] = (o % mod); } int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; --a; --b; v[a].push_back(b); rev[b].push_back(a); } int ok = 1; create_topo(0); reverse_trav(1); for (int u : loops) { if (reachable[u]) { ok = 0; } } if (!ok) { cout << "inf\n"; return 0; } long z = calc(1); if (z > (long) 1e9) pad = 1; z %= (long) 1e9; string b = to_string(z); if (pad && b.size() != 9) b = string(9 - b.size(), '0') + b; cout << b << "\n"; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
8 14
6 7 6 8 7 5 5 2 ... |
correct output |
---|
6 |
user output |
---|
6 |
Test 2
Verdict: ACCEPTED
input |
---|
10 23
9 7 3 5 7 3 6 3 ... |
correct output |
---|
34 |
user output |
---|
34 |
Test 3
Verdict: ACCEPTED
input |
---|
20 33
10 15 15 17 8 18 12 5 ... |
correct output |
---|
9 |
user output |
---|
9 |
Test 4
Verdict: ACCEPTED
input |
---|
20 32
3 12 4 3 16 14 18 6 ... |
correct output |
---|
12 |
user output |
---|
12 |
Test 5
Verdict: ACCEPTED
input |
---|
100 2515
81 85 44 37 96 24 76 47 ... |
correct output |
---|
045764845 |
user output |
---|
045764845 |
Test 6
Verdict: ACCEPTED
input |
---|
2000 17506
773 455 197 97 1919 1803 547 1424 ... |
correct output |
---|
158163175 |
user output |
---|
158163175 |
Test 7
Verdict: ACCEPTED
input |
---|
1000 2302
466 579 722 97 665 207 164 595 ... |
correct output |
---|
000000004 |
user output |
---|
000000004 |
Test 8
Verdict: ACCEPTED
input |
---|
5000 94881
449 897 2606 1774 3582 4224 3404 3796 ... |
correct output |
---|
735358770 |
user output |
---|
735358770 |
Test 9
Verdict: ACCEPTED
input |
---|
10000 99361
8997 968 8498 5208 6917 736 7724 451 ... |
correct output |
---|
526200210 |
user output |
---|
526200210 |
Test 10
Verdict: ACCEPTED
input |
---|
10000 89720
3708 9853 7 5030 1366 275 8433 4123 ... |
correct output |
---|
460441436 |
user output |
---|
460441436 |