QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#67861 | #4885. Triangular Cactus Paths | 275307894a | WA | 53ms | 34496kb | C++14 | 2.0kb | 2022-12-12 20:16:35 | 2022-12-12 20:16:38 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define PB push_back
using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned ll;
using namespace std;const int N=4e5+5,M=3e5+5,K=1e5+5,mod=998244353,Mod=mod-1;const ll INF=1e18+7;const db eps=1e-5;mt19937 rnd(time(0));
int fa[N][20],lg[N],d[N],q,n,m,k,x,y,z,Ct,frc[N],Inv[N],Q[N];vector<int> S[N],G[N];void con(int x,int y){G[x].PB(y);G[y].PB(x);}
ll mpow(ll x,int y=mod-2){ll Ans=1;while(y) y&1&&(Ans=Ans*x%mod),y>>=1,x=x*x%mod;return Ans;}
namespace SCC{
int dh,dfn[N],low[N],st[N],sh;void Tarjan(int x,int La){
dfn[x]=low[x]=++dh;st[++sh]=x;for(int i:S[x])if(i^La){
if(dfn[i]){low[x]=min(low[x],dfn[i]);continue;}Tarjan(i,x);low[x]=min(low[x],low[i]);
if(dfn[x]<=low[i]){if(st[sh]==i) {con(x,i);sh--;continue;}++Ct;con(Ct,x);while(st[sh+1]^i) con(st[sh],Ct),sh--;}
}
}
void BD(){for(int i=1;i<=n;i++) Tarjan(i,0);}
}
void Make(int x,int La){d[x]=d[La]+1;fa[x][0]=La;Q[x]=Q[La]+(x>n);for(int i=1;fa[x][i-1];i++) fa[x][i]=fa[fa[x][i-1]][i-1];for(int i:S[x]) i^La&&(Make(i,x),0);}
int LCA(int x,int y){d[x]<d[y]&&(swap(x,y),0);while(d[x]^d[y]) x=fa[x][lg[d[x]-d[y]]];if(x==y) return x;for(int i=lg[d[x]];~i;i--) fa[x][i]^fa[y][i]&&(x=fa[x][i],y=fa[y][i]);return fa[x][0];}
ll C(int x,int y){if(y<0||y>x) return 0;return frc[x]*Inv[y]%mod*Inv[x-y]%mod;}
int main(){
int i,j;scanf("%d%d",&n,&m);for(i=1;i<=m;i++) scanf("%d%d",&x,&y),S[x].PB(y),S[y].PB(x);Ct=n;SCC::BD();for(i=2;i<=Ct;i++) lg[i]=lg[i/2]+1;for(i=1;i<=Ct;i++) swap(S[i],G[i]);Make(1,0);
for(Inv[0]=frc[0]=i=1;i<=Ct;i++) frc[i]=frc[i-1]*i%mod,Inv[i]=mpow(frc[i]);scanf("%d",&q);while(q--){
scanf("%d%d%d",&x,&y,&k);int Ls=LCA(x,y);
printf("%lld\n",C(Q[x]+Q[y]-Q[Ls]-Q[fa[Ls][0]],k-(d[x]+d[y]-2*d[Ls]-(Q[x]+Q[y]-Q[Ls]-Q[fa[Ls][0]]))));
}
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 32260kb
input:
8 10 1 2 2 3 3 1 3 4 4 5 5 6 6 4 4 7 7 8 8 4 6 1 1 0 1 1 1 1 4 3 6 2 4 5 7 4 3 4 2
output:
1 0 1 2 1 0
result:
ok 6 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 34496kb
input:
2 1 1 2 8 1 1 0 1 1 1 1 2 0 1 2 1 2 1 0 2 1 1 2 2 0 2 2 1
output:
1 0 0 1 0 1 1 0
result:
ok 8 numbers
Test #3:
score: -100
Wrong Answer
time: 53ms
memory: 34444kb
input:
50 70 41 24 9 15 29 19 21 11 1 14 5 27 34 48 10 32 34 49 46 3 22 33 34 39 16 30 22 45 7 16 25 30 43 17 22 44 5 25 41 49 29 32 39 25 10 4 45 27 13 38 29 7 3 35 14 30 50 2 8 11 13 35 18 26 34 40 38 36 7 19 12 3 25 26 30 42 21 8 12 46 44 33 14 31 47 2 25 46 20 19 49 24 15 43 18 25 13 36 27 22 4 32 30 3...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 -301989881 0 0 0 0 0 -301989880 0 0 -103109731 578813992 0 -671088175 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -524287958 2 0 0 0 0 0 -813694951 0 0 0 0 0 0 0 0 201329839 0 0 0 0 -301989881 0 -813694951 0 0 0 0 201329839 0 -813694951 0 0...
result:
wrong answer 33rd numbers differ - expected: '3', found: '-301989881'