LOADING

加载过慢请开启缓存,浏览器默认开启

daily 2

2023/7/17 daily

CF 1121D

ll a[MAXN],b[MAXN];
ll dp[MAXN][3];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int q;
    cin>>q;
    memset(dp,0x3f,sizeof(dp));
    while(q--){
        int n;
        cin>>n;
        for(int i=1;i<=n;++i){
            cin>>a[i]>>b[i];
        }
        for(int i=0;i<=n;++i)dp[i][0]=dp[i][1]=dp[i][2]=INF;
        dp[0][0]=0;
        for(int i=1;i<=n;++i){
            for(int k1=0;k1<3;++k1){
                for(int k2=0;k2<3;++k2){
                    if(a[i-1]+k2!=a[i]+k1){
                        dp[i][k1]=min(dp[i][k1],dp[i-1][k2]+b[i]*k1);
                    }
                }
            }
        }
        ll ans=INF;
        for(int i=0;i<3;++i){
            ans=min(ans,dp[n][i]);
        }
        cout<<ans<<'\n';
    }
}

CF 1172B

int main(){
    int n;
    cin>>n;
    ll ans=n;
    vector<ll>deg(n+1);
    for(int i=1;i<=n-1;++i){
        int u,v;
        cin>>u>>v;
        deg[v]++;
        deg[u]++;
        ans=ans*deg[u]%MOD*deg[v]%MOD;
    }
    cout<<ans<<"\n";
    return 0;
}