Advertisement
tuki2501

coci06c3p5.cpp

Jan 30th, 2022
819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // ----------- define --------------
  5. #define int long long
  6. #define vi vector<int>
  7. #define ii pair<int,int>
  8. #define fi first
  9. #define sc second
  10. #define mp make_pair
  11. #define pqueue priority_queue
  12. #define popcnt __builtin_popcount
  13. #define getBit(x, k) ((x >> k) & 1)
  14. #define all(x) (x).begin(),(x).end()
  15. // ---------------------------------
  16.  
  17. const int N = 10005;
  18. const int mod = 1e9;
  19.  
  20. int vst[N], ist[N], cnt[N], cdd[N];
  21. vector<int> rev[N];
  22.  
  23. int flag = 0;
  24.  
  25. int cal(int i) {
  26.   if (ist[i]) {
  27.     if (i != 2) cdd[i] = 1;
  28.     return 0;
  29.   }
  30.   if (vst[i]) return cnt[i];
  31.   vst[i] = ist[i] = 1;
  32.   if (i == 1) cnt[i] = 1;
  33.   for (auto &j : rev[i]) {
  34.     cnt[i] += cal(j);
  35.     if (cnt[i] >= mod) {
  36.       cnt[i] -= mod;
  37.       flag = 1;
  38.     }
  39.   }
  40.   if (cdd[i] && cnt[i]) {
  41.     cout << "inf" << '\n';
  42.     exit(0);
  43.   }
  44.   ist[i] = 0;
  45.   return cnt[i];
  46. }
  47.  
  48. void Main() {
  49.   int n, m;
  50.   cin >> n >> m;
  51.   for (int i = 1; i <= m; i++) {
  52.     int u, v;
  53.     cin >> u >> v;
  54.     rev[v].push_back(u);
  55.   }
  56.   int ans = cal(2);
  57.   if (!flag) cout << ans << '\n';
  58.   else cout << setw(9) << setfill('0') << ans << '\n';
  59. }
  60.  
  61. signed main() {
  62. #ifdef _DEBUG
  63.   // freopen("in" , "r", stdin );
  64.   cerr << "- ---- -- ----- <3\n";
  65. #endif
  66.   cin.tie(0)->sync_with_stdio(0);
  67.   int T = 1;
  68.   // cin >> T;
  69.   while (T--) Main();
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement