結果

問題 No.1340 おーじ君をさがせ
ユーザー milanis48663220
提出日時 2021-01-15 22:40:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 3,095 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 98,300 KB
最終ジャッジ日時 2025-01-17 20:01:48
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 59
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
class Bit{
public:
bool v;
Bit(bool _v = false){
v = _v;
}
Bit operator+(bool b){
return Bit(v|b);
}
Bit operator*(bool b){
return Bit(v&b);
}
void operator+=(bool b){
v |= b;
}
void operator*=(bool b){
v &= b;
}
Bit operator+(Bit b){
return Bit(v|b.v);
}
Bit operator*(Bit b){
return Bit(v&b.v);
}
void operator+=(Bit b){
v |= b.v;
}
void operator*=(Bit b){
v &= b.v;
}
};
template <typename T>
struct matrix{
int n, m;
vector<vector<T>> dat;
matrix(int n_, int m_){
n = n_; m = m_;
for(int i = 0; i < n; i++){
dat.push_back(vector<T>(m));
}
}
vector<T>& operator[](int x) {
return dat[x];
}
};
template <typename T>
bool prod(matrix<T> a, matrix<T> b, matrix<T> &ans){
assert(a.m == b.n);
for(int i = 0; i < a.n; i++){
for(int j = 0; j < b.m; j++){
ans.dat[i][j] = 0;
for(int k = 0; k < b.n; k++){
ans.dat[i][j] += (a.dat[i][k]*b.dat[k][j]);
}
}
}
return true;
}
template <typename T>
void copy_mat(matrix<T> a, matrix<T> &b){
assert(a.n == b.n);
assert(a.m == b.m);
for(int i = 0; i < a.n; i++){
for(int j = 0; j < a.m; j++){
b.dat[i][j] = a.dat[i][j];
}
}
}
template <typename T>
void pow_mat(matrix<T> a, ll n, matrix<T> &ans){
assert(n < ((ll)1<<61));
matrix<T> buf(a.n, a.n);
matrix<T> tmp(a.n, a.n);
copy_mat(a, tmp);
for(int i = 0; i < a.n; i++) {
for(int j = 0; j < a.n; j++){
ans.dat[i][j] = 0;
}
ans.dat[i][i] = 1;
}
for(int i = 0; i <= 60; i++){
ll m = (ll)1 << i;
if(m&n){
prod(tmp, ans, buf);
copy_mat(buf, ans);
}
prod(tmp, tmp, buf);
copy_mat(buf, tmp);
}
}
int n, m;
ll t;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
cin >> n >> m >> t;
matrix<Bit> mat(n, n);
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b;
mat[b][a] = true;
}
matrix<Bit> v(n, 1);
v[0][0] = true;
matrix<Bit> pw(n, n);
pow_mat(mat, t, pw);
matrix<Bit> ans(n, 1);
prod(pw, v, ans);
// cout << ans << endl;
int sum = 0;
for(int i = 0; i < n; i++) {
if(ans[i][0].v) sum++;
}
cout << sum << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0