結果
問題 | No.1340 おーじ君をさがせ |
ユーザー |
![]() |
提出日時 | 2021-01-15 22:08:52 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 72 ms / 2,000 ms |
コード長 | 3,646 bytes |
コンパイル時間 | 5,891 ms |
コンパイル使用メモリ | 165,364 KB |
最終ジャッジ日時 | 2025-01-17 19:31:33 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 59 |
ソースコード
#pragma GCC target ("avx2")// #pragma GCC optimization ("O3")#pragma GCC optimization ("unroll-loops")#include <iostream>#include <array>#include <algorithm>#include <vector>#include <bitset>#include <set>#include <unordered_set>#include <cmath>#include <complex>#include <deque>#include <iterator>#include <numeric>#include <map>#include <unordered_map>#include <queue>#include <stack>#include <string>#include <tuple>#include <utility>#include <limits>#include <iomanip>#include <functional>#include <cassert>// #include <atcoder/all>using namespace std;using ll=long long;template<class T> using V = vector<T>;template<class T, class U> using P = pair<T, U>;using vll = V<ll>;using vii = V<int>;using vvll = V<vll>;using vvii = V< V<int> >;using PII = P<int, int>;using PLL = P<ll, ll>;#define RevREP(i,n,a) for(ll i=n;i>a;i--) // (a,n]#define REP(i,a,n) for(ll i=a;i<n;i++) // [a,n)#define rep(i, n) REP(i,0,n)#define ALL(v) v.begin(),v.end()#define eb emplace_back#define pb push_back#define sz(v) int(v.size())template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }template< class A, class B > ostream& operator <<(ostream& out, const P<A, B> &p) {return out << '(' << p.first << ", " << p.second << ')';}template< class A > ostream& operator <<(ostream& out, const V<A> &v) {out << '[';for (int i=0;i<int(v.size());i++) {if (i) out << ", ";out << v[i];}return out << ']';}const long long MOD = 1000000007;const long long HIGHINF = (long long)1e18;const int INF = (int)1e9;template <typename T>struct mat {int h, w;std::vector< std::vector<T> > d;mat() {}mat(int h, int w, T v=T(0)): h(h), w(w), d(h, std::vector<T>(w, v)){}std::vector<T>& operator[] (int i) {return d[i];}const std::vector<T>& operator[] (int i) const { return d[i];}void fil(T v=T(0)) { for(int i=0;i<h;i++) for(int j=0;j<w;j++) d[i][j] = v;}void unit() { for(int i=0;i<h;i++) for(int j=0;j<w;j++) d[i][j] = T(i==j);}mat<T> operator+(const mat<T>& a) const { // same sizemat<T> res(h,w);for (int i = 0; i < h; i++) {for (int j = 0; j < w; j++) {res[i][j] = d[i][j]+a[i][j];}}return res;}mat<T> operator-(const mat<T>& a) const { // same sizemat<T> res(h,w);for (int i = 0; i < h; i++) {for (int j = 0; j < w; j++) {res[i][j] = d[i][j]-a[i][j];}}return res;}mat<T> operator*(const mat<T>& a) const { // w = a.hmat<T> res(h,a.w);for (int i = 0; i < h; i++) {for (int k = 0; k < w; k++) {for (int j = 0; j < a.w; j++) {res[i][j] |= d[i][k]&a[k][j];}}}return res;}mat<T> power(ll a) { // h = wmat<T> ret(h, w), me = *this;ret.unit();while (a > 0) {if (a & 1) ret = ret * me;me = me * me;a >>= 1;}return ret;}};int main() {cin.tie(0);ios::sync_with_stdio(false);ll n, m, t; cin >> n >> m >> t;vvii edges(n, vii(n, 0));rep(i, m) {int a, b; cin >> a >> b;edges[a][b] = 1;}mat<int> mmm(n, n, 0);mmm.d = edges;mat<int> am = mmm.power(t);int ans = 0;rep(i, n) ans += am[0][i];cout << ans << '\n';return 0;}