提出 #22020766
ソースコード 拡げる
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
using mint = modint1000000007;
template<class T> struct mat{
int n,m;
std::vector<std::vector<T>> v;
T a;
explicit mat(int e=0):n(-1),m(-1),v(){
if(e==0) m=0;
if(e==1) m=1;
}
mat(int n,int m,T e):n(n),m(m),v(n,std::vector<T>(m)){
for(int i{};i<(n);++i){
if(i<m) v[i][i]=e;
}
}
mat(std::vector<std::vector<T>>& v):n(v.size()),m(v[0].size()),v(std::move(v)){}
bool operator==(const mat& x){
if(n!=x.n||m!=x.m) return false;
for(int i{};i<(n);++i){
for(int j{};j<(m);++j){
if(v[i][j]!=x.v[i][j]) return false;
}
}
return true;
}
mat& operator=(const mat& x) = default;
mat operator+(const mat& x){
if(n==-1&&m==0) return x;
if(x.n==-1&&x.m==0) return *this;
assert(n==x.n and m==x.m);
auto y=std::vector(n,std::vector<T>(m));
for(int i{};i<(n);++i){
for(int j{};j<(m);++j){
y[i][j]=v[i][j]+x.v[i][j];
}
}
return mat(y);
}
mat operator-(const mat& x){
if(n==-1&&m==0){
auto y=std::vector(x.n,std::vector<T>(x.m));
for(int i{};i<(x.n);++i){
for(int j{};j<(x.m);++j){
y[i][j]=T()-x.v[i][j];
}
}
return mat(y);
}
if(x.n==-1&&x.m==0) return *this;
if(n!=x.n||m!=x.m) return mat();
auto y=std::vector(x.n,std::vector<T>(x.m));
for(int i{};i<(x.n);++i){
for(int j{};j<(x.m);++j){
y[i][j]=v[i][j]-x.v[i][j];
}
}
return mat(y);
}
mat operator*(const mat& x){
if(n==-1&&m==1) return x;
if(x.n==-1&&x.m==1) return *this;
assert(m==x.n);
auto y=std::vector(x.n,std::vector<T>(x.m));
for(int i{};i<(n);++i){
for(int k{};k<(m);++k){
for(int j{};j<(x.m);++j){
y[i][j]+=v[i][k]*x.v[k][j];
}
}
}
return mat(y);
}
mat& operator+=(const mat& x){
assert(n==x.n and m==x.m);
for(int i{};i<(n);++i){
for(int j{};j<(m);++j){
v[i][j]+=x.v[i][j];
}
}
return *this;
}
mat& operator-=(const mat& x){
assert(n==x.n and m==x.m);
for(int i{};i<(n);++i){
for(int j{};j<(m);++j){
v[i][j]-=x.v[i][j];
}
}
return *this;
}
mat& operator*=(const mat& x){
*this=*this*x;
return *this;
}
T& operator()(int i,int j){
if(n==-1){
if(m==1&&i==j) a=T(1);
return a;
}
return v[i][j];
}
T det(){
if(n==0){
if(m==0) return T();
if(m==1) return T(1);
}
if(n!=m) return T();
mat y=*this;
int c=1;
for(int i=0;i<n;++i){
for(int j=i;j<n;++j){
if(v[j][i]!=T()){
if(i!=j){
swap(v[i],v[j]);
c*=-1;
}
break;
}
if(j==n-1) return T();
}
for(int j=i+1;j<n;++j){
T ka=v[j][i]/v[i][i];
for(int k=i;k<n;k++){
v[j][k]-=v[i][k]*ka;
}
}
}
T d=T(1);
for(int i=0;i<n;i++) d*=v[i][i];
d*=c;
*this=y;
return d;
}
void print(){
if(n<0){
std::cout<<"("<<m<<")"<<std::endl;
return;
}
for(int i{};i<(n);++i){
for(int j{};j<(m);++j){
std::cout<<v[i][j]<<" ";
}
std::cout<<std::endl;
}
}
};
template<class T,class U>
T pw(T n,U m){
T ans(1),tmp(n);
while(m){
if(m&1) ans*=tmp;
m>>=1;
tmp*=tmp;
}
return ans;
}
void solve(){
int n,m,k;
cin >> n >> m>> k;
vector<vector<mint>> a(n,vector<mint>(1));
int tmp;
for(auto&i:a){
cin>>tmp;
i[0]=tmp;
}
mint iv=mint(m).inv(), iv2=iv/2;
vector<vector<mint>> e(n,vector<mint>(n));
for(int i{},x,y;i<(m);++i){
cin>>x>>y;
--x,--y;
for(int i{};i<(n);++i){
if(i!=x and i!=y){
e[i][i]+=iv;
}
}
e[x][x]+=iv2;
e[x][y]+=iv2;
e[y][x]+=iv2;
e[y][y]+=iv2;
}
for(auto v:(pw(mat<mint>(e),k)*mat<mint>(a)).v){
cout<<v[0].val()<<'\n';
}
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
}
提出情報
| 提出日時 |
|
| 問題 |
F - Graph Smoothing |
| ユーザ |
Motsu_xe |
| 言語 |
C++ (GCC 9.2.1) |
| 得点 |
600 |
| コード長 |
5259 Byte |
| 結果 |
AC |
| 実行時間 |
87 ms |
| メモリ |
3852 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
600 / 600 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
| All |
handmade_00.txt, handmade_01.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| handmade_00.txt |
AC |
12 ms |
3564 KiB |
| handmade_01.txt |
AC |
2 ms |
3668 KiB |
| random_00.txt |
AC |
87 ms |
3728 KiB |
| random_01.txt |
AC |
44 ms |
3828 KiB |
| random_02.txt |
AC |
87 ms |
3844 KiB |
| random_03.txt |
AC |
84 ms |
3852 KiB |
| random_04.txt |
AC |
86 ms |
3852 KiB |
| random_05.txt |
AC |
2 ms |
3660 KiB |
| random_06.txt |
AC |
65 ms |
3812 KiB |
| random_07.txt |
AC |
11 ms |
3732 KiB |
| random_08.txt |
AC |
59 ms |
3752 KiB |
| random_09.txt |
AC |
84 ms |
3808 KiB |
| random_10.txt |
AC |
9 ms |
3796 KiB |
| random_11.txt |
AC |
51 ms |
3732 KiB |
| random_12.txt |
AC |
16 ms |
3692 KiB |
| random_13.txt |
AC |
43 ms |
3784 KiB |
| random_14.txt |
AC |
15 ms |
3608 KiB |
| random_15.txt |
AC |
79 ms |
3832 KiB |
| random_16.txt |
AC |
20 ms |
3728 KiB |
| random_17.txt |
AC |
3 ms |
3652 KiB |
| random_18.txt |
AC |
12 ms |
3608 KiB |
| random_19.txt |
AC |
9 ms |
3724 KiB |
| random_20.txt |
AC |
14 ms |
3676 KiB |
| random_21.txt |
AC |
2 ms |
3608 KiB |
| random_22.txt |
AC |
10 ms |
3704 KiB |
| random_23.txt |
AC |
60 ms |
3736 KiB |
| sample_01.txt |
AC |
2 ms |
3656 KiB |
| sample_02.txt |
AC |
2 ms |
3636 KiB |
| sample_03.txt |
AC |
2 ms |
3612 KiB |