QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#125864#6738. Cover__stickWA 788ms32476kbC++203.6kb2023-07-17 20:17:322023-07-17 20:17:35

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-17 20:17:35]
  • 评测
  • 测评结果:WA
  • 用时:788ms
  • 内存:32476kb
  • [2023-07-17 20:17:32]
  • 提交

answer

#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
using namespace std;
template<typename T>
inline bool cmax(T&x,const T& y){return x<y?x=y,1:0;}
template<typename T>
inline bool cmin(T&x,const T& y){return y<x?x=y,1:0;}
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vii; 
typedef unsigned long long ull;
#define sz(x) (int(x.size()))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define em emplace
#define X first
#define Y second
const int mod=998244353;
inline void MOD(int&x){x-=mod,x+=x>>31&mod;}
inline void MOD(ll& x){x-=mod,x+=x>>63&mod;}
inline int add(int x,int y){MOD(x+=y);return x;}
inline int mul(int x,int y){return 1ll*x*y%mod;}
template<typename ... A>inline int mul(const int& x,const A&... p){return 1ll*x*mul(p...)%mod;}
inline ll ksm(ll a,ll p=mod-2){ll ans=1;for(;p;p>>=1,a=a*a%mod)if(p&1)ans=ans*a%mod;return ans;}
typedef long double LD;
constexpr int MAXN=1e5+10;
struct BIT
{
    ll t[MAXN];
    inline void add(int x,int k){for(;x<MAXN;x+=x&=x)t[x]+=k;}
    inline ll ask(int x){ll ans=0;for(;x;x-=x&-x)ans+=t[x];return ans;}
    inline ll ask(int l,int r){return ask(r)-ask(l-1);}
}t;
int dfn[MAXN],top[MAXN],d[MAXN],fa[MAXN],siz[MAXN],son[MAXN];
vi e[MAXN];
void dfs(int u)
{
    siz[u]=1;
    for(auto&v:e[u])if(v!=fa[u])
    {
        fa[v]=u,d[v]=d[u]+1,dfs(v),siz[u]+=siz[v];
        if(siz[son[u]]<siz[v])son[u]=v;
    }
}
void pf(int u,int tp)
{
    static int tt;
    dfn[u]=++tt,top[u]=tp;
    if(!son[u])return;
    pf(son[u],tp);
    for(auto&v:e[u])if(v!=fa[u]&&v!=son[u])pf(v,v);
}
inline int LCA(int u,int v)
{
    while(top[u]!=top[v])d[top[u]]>d[top[v]]?u=fa[top[u]]:v=fa[top[v]];
    return d[u]<d[v]?u:v;
}
inline int jump(int u,int v)
{
    int la=-1;
    while(top[v]!=top[u])la=top[v],v=fa[la];
    if(v==u)return la;
    else return son[u];
}
ll tot[MAXN];
ll F[MAXN][13];
int id[MAXN];
inline ll getsum(int u,int v)
{
    //return 0;
    ll ans=tot[v]-F[v][id[son[v]]];
    while(top[u]!=top[v])
    {
        ans+=F[fa[top[v]]][id[top[v]]]-F[fa[top[v]]][id[son[fa[top[v]]]]];
        ans+=t.ask(dfn[top[v]],dfn[v]);
        v=fa[top[v]];
    }
    ans+=t.ask(dfn[u],dfn[v]);
    return ans;
}
vector<tuple<int,int,int> >ve[MAXN];
void dp(int u)
{
    if(u!=1)e[u].erase(find(all(e[u]),fa[u]));
    for(auto&v:e[u])dp(v);
    int m=sz(e[u]);
    vector<ll> F(1<<m);
    int cnt=0;
    for(auto&v:e[u])
    {
        id[v]=cnt++;
        int S=(1<<m)-1;S^=1<<id[v];
        for(int s=S;s;s=S&(s-1))cmax(F[s|(1<<id[v])],F[s]+tot[v]);
        cmax(F[1<<id[v]],tot[v]);
    }
  //  cerr<<"!\n";
    for(auto&[x,y,w]:ve[u])
    {
        int st=0;
        ll res=w;
        if(x!=u)
        {
            int xx=jump(u,x);
            res+=getsum(xx,x);
            st|=1<<id[xx];
        }
        if(y!=u)
        {
            int yy=jump(u,y);
            res+=getsum(yy,y);
            st|=1<<id[yy];
        }
        int S=(1<<m)-1;S^=st;
        for(int s=S;s;s=S&(s-1))cmax(F[s|st],F[s]+res);
        cmax(F[st],res);
    }
    for(int i=0;i<m;i++)::F[u][i]=F[((1<<m)-1)^(1<<i)];
    tot[u]=F[(1<<m)-1];
    t.add(dfn[u],::F[u][id[son[u]]]);
}
int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);cout<<fixed<<setprecision(10);
    int n,m,k;cin>>n>>m>>k;
    for(int i=1,u,v;i<n;i++)cin>>u>>v,e[u].emplace_back(v),e[v].emplace_back(u);
    dfs(1),pf(1,1);
    for(int i=1,x,y,w;i<=m;i++)
    {
        cin>>x>>y>>w;
        ve[LCA(x,y)].emplace_back(x,y,w);
    }
    dp(1);
    cout<<tot[1];
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 13548kb

input:

5 7 3
1 2
1 3
2 4
2 5
3 2 8
5 4 10
3 1 2
1 2 7
2 1 2
1 2 1
5 2 3

output:

19

result:

ok 1 number(s): "19"

Test #2:

score: -100
Wrong Answer
time: 788ms
memory: 32476kb

input:

100000 500000 12
2 1
3 2
4 2
5 2
6 5
7 2
8 5
9 3
10 2
11 2
12 5
13 1
14 1
15 1
16 1
17 1
18 1
19 1
20 1
21 1
22 1
23 1
24 12
25 2
26 2
27 2
28 2
29 2
30 15
31 30
32 23
33 26
34 22
35 30
36 26
37 3
38 3
39 3
40 3
41 3
42 3
43 3
44 3
45 3
46 3
47 20
48 21
49 4
50 4
51 4
52 4
53 4
54 4
55 4
56 4
57 4
5...

output:

656678299382

result:

wrong answer 1st numbers differ - expected: '660925834533', found: '656678299382'