QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#657047#9488. Do Not Turn Backucup-team3161#WA 3ms9232kbC++203.3kb2024-10-19 14:06:062024-10-19 14:06:12

Judging History

你现在查看的是最新测评结果

  • [2024-10-19 14:06:12]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9232kb
  • [2024-10-19 14:06:06]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	return f?-x:x;
}

#define mod 998244353
struct modint{
	unsigned int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x<o.x?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,modint b){return a.x==b.x;}
	friend bool operator !=(modint a,modint b){return a.x!=b.x;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 1000005
#define inf 0x3f3f3f3f

int n,m,k;

struct mat{
    modint f[105][105];
    modint*operator [](int x){return f[x];}
};
mat operator *(mat a,mat b){
    mat c;
    For(i,1,n)For(k,1,n)For(j,1,n)
        c[i][j]+=a[i][k]*b[k][j];
    return c;
}
mat operator +(mat a,mat b){
    For(i,1,n)For(j,1,n)a[i][j]+=b[i][j];
    return a;
}
void operator +=(mat&a,mat b){
    For(i,1,n)For(j,1,n)a[i][j]+=b[i][j];
}

struct mat2{
    mat f[2][2];
};
mat2 operator *(mat2 a,mat2 b){
    mat2 c;
    For(i,0,1)For(k,0,1)For(j,0,1)
        c.f[i][j]+=a.f[i][k]*b.f[k][j];
    return c;
}

struct line2{
    mat f[2];
};

int eu[maxn],ev[maxn],deg[maxn];

void work()
{
    n=read(),m=read(),k=read();
    For(i,1,m) eu[i]=read(),ev[i]=read(),++deg[eu[i]],++deg[ev[i]];
    if(k<=2) puts("0"),exit(0);
    mat I,D;
    For(i,1,n) I[i][i]=1,D[i][i]=(1-deg[i]+mod)%mod;
    mat E;
    For(i,1,m) E[eu[i]][ev[i]]=E[ev[i]][eu[i]]=1;
    mat EE=E*E;
    For(i,1,n) EE[i][i]=0;
    mat2 f;
    f.f[0][1]=D;
    f.f[1][1]=E;
    f.f[1][0]=I;
    mat2 p=f;
    k-=2;
    int lg=20;
    while(!(k>>lg&1))--lg;
    Rep(i,lg-1,0){
        p=p*p;
        if(k>>i&1) p=p*f;
    }
    mat res=E*p.f[0][1]+EE*p.f[1][1];
    modint out=0;
    out=res[1][n];
    cout<<out.x;
}
/*
8 1
5 8 5 1

*/

signed main()
{
    work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9224kb

input:

6 8 5
1 2
1 3
2 3
2 4
3 5
4 5
4 6
5 6

output:

2

result:

ok "2"

Test #2:

score: 0
Accepted
time: 3ms
memory: 9232kb

input:

11 11 2023
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
1 11

output:

1

result:

ok "1"

Test #3:

score: 0
Accepted
time: 3ms
memory: 9156kb

input:

7 21 1000000000
1 2
1 3
1 4
1 5
1 6
1 7
2 3
2 4
2 5
2 6
2 7
3 4
3 5
3 6
3 7
4 5
4 6
4 7
5 6
5 7
6 7

output:

405422475

result:

ok "405422475"

Test #4:

score: -100
Wrong Answer
time: 3ms
memory: 9216kb

input:

12 56 78144853
1 2
1 3
1 4
1 6
1 7
1 9
1 10
1 11
1 12
2 4
2 5
2 6
2 8
2 9
2 10
2 11
2 12
3 4
3 5
3 6
3 7
3 8
3 9
3 11
3 12
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
5 6
5 7
5 8
5 9
5 10
5 11
5 12
6 8
6 9
6 10
7 8
7 9
7 11
7 12
8 9
8 10
8 11
8 12
9 10
9 11
9 12
10 11
11 12

output:

74341485

result:

wrong answer 1st words differ - expected: '843326021', found: '74341485'