結果
| 問題 | No.1340 おーじ君をさがせ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-15 21:52:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 74 ms / 2,000 ms |
| コード長 | 721 bytes |
| 記録 | |
| コンパイル時間 | 782 ms |
| コンパイル使用メモリ | 73,216 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-27 23:07:20 |
| 合計ジャッジ時間 | 3,066 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 59 |
コンパイルメッセージ
main.cpp:19:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
19 | main()
| ^~~~
ソースコード
#include<iostream>
#include<vector>
using namespace std;
vector<vector<int> >mul(const vector<vector<int> >&A,const vector<vector<int> >&B)
{
int N=A.size();
vector<vector<int> >ret(N,vector<int>(N));
for(int i=0;i<N;i++)for(int j=0;j<N;j++)
{
int cnt=0;
for(int k=0;k<N;k++)
{
cnt+=A[i][k]*B[k][j];
}
if(cnt)ret[i][j]=1;
}
return ret;
}
main()
{
int N,M;
long T;
cin>>N>>M>>T;
vector<vector<int> >G(N,vector<int>(N));
for(int i=0;i<M;i++)
{
int a,b;cin>>a>>b;
G[b][a]=1;
}
vector<vector<int> >E(N,vector<int>(N));
for(int i=0;i<N;i++)E[i][i]=1;
while(T)
{
if(T&1)
{
E=mul(E,G);
}
T>>=1;
G=mul(G,G);
}
int ans=0;
for(int i=0;i<N;i++)if(E[i][0])ans++;
cout<<ans<<endl;
}