QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#373501#6381. LaLa and Harvestingwilly109WA 1ms3852kbC++204.9kb2024-04-01 19:25:232024-04-01 19:25:24

Judging History

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

  • [2024-04-01 19:25:24]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3852kb
  • [2024-04-01 19:25:23]
  • 提交

answer

#include <bits/stdc++.h>

#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define ld long double
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define int long long 
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cout <<#x << " : " << x << "\n" ;
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 502 + 10, sq = 44 , lg = 19,  inf = 1e18+10 ;
int dp[2*maxn][(1<<4)+1] , ch[maxn ],w[maxn] , bl[maxn] , mark[maxn] , dis[maxn], ok[maxn] ;
pii par[2*maxn][(1<<4)+1] ; 
vector <int> G[maxn] , T[maxn] , vec[maxn] , tr[maxn]  ;
int cnt = 1; 
void bui(int v){
    mark[v] = 1 ;
    vec[v].pb(cnt) ;cnt++ ; 
    bl[v] = -1 ;
    for(int u : G[v]){
        if(mark[u] == 1){
            if(dis[u]+1 < dis[v]){
                bl[v] = u ;
                ch[v] = 1;  
            }
            continue ;
        }
        dis[u] = dis[v] + 1; 
        bui(u) ;
        if(bl[v]== -1 && bl[u] != v)bl[v] = bl[u] ;
        vec[v].pb(cnt);cnt++;
        T[v].pb(u) ;
    }
}
inline int c(int x ,int y){
    return (x>>y&1) ;
}
inline int f(int a ,int b, int c, int d){
    return a+b*2+c*4+d*8 ; 
}

void dfs(int v){
    for(int u : T[v]){
        dfs(u) ;
    }
    int id = vec[v][0] ;
    if(sz(T[v]) == 0){
        rep(i , 0 , 15)dp[id][i] = -inf ;
        rep(i , 0 , 1){
            if(ok[v] == 0 && i)continue ;
            dp[id][i*(1+2+4)+(bl[v]!=-1 ? i : 0)*8] = (i==1 ? w[v] : 0) ;         
        }
        return  ;
    }
    rep(i , 0 , 15)dp[id][i] = -inf ;
    rep(i , 0 , 1){
        rep(j , 0 , 1){
            if(ok[v]==0 && i)continue ;
            if(ch[v] == 1 && j!=i)continue ;
            dp[id][i+j*8] = (i==1 ? w[v] : 0) ;
        }
    }
    rep(k , 0 , sz(T[v])-1){
        int u = T[v][k] ;
        id = vec[v][k+1] ;int id2 = vec[v][k] ;
        rep(i ,0 , 15)dp[id][i] = -inf ;
        rep(i , 0 , 15){
            rep(j , 0 , 15){
                if(c(i,0)&c(j,0))continue ;
                if(bl[u] == v && (c(i,0)&c(j,3)))continue ;
                if(c(i , 2)&c(j , 1))continue ;
                int x = f(c(i,0) , (k==0?c(j,1):c(i,1)) , c(j , 2) , ((bl[u]!=-1 && bl[u]!=v) ? c(j , 3) : c(i , 3)));  
                if(dp[id][x] < dp[vec[u].back()][j]+dp[id2][i]){
                    dp[id][x] = dp[vec[u].back()][j]+dp[id2][i] ;
                    par[id][x] = {i,j};
                }
            }
        }
    }
}
map<int,int>ed[maxn]; 
vector<int> A ;


void cp(int v , int ms){
    if(ms&1)A.pb(v) ;
    per(i , sz(vec[v])-1 , 1){
        int id = vec[v][i] ;
        cp(T[v][i-1] , par[id][ms].S) ;
        ms = par[id][ms].F ;
    }
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n , m ;
    cin >> n >> m ;
    rep(i , 1, n)cin >> w[i] ;
    rep(i , 1, m){
        int v, u;
        cin >> v >> u ;
        v++ ; u++;
        G[v].pb(u);
        G[u].pb(v) ;
    }
    bui(1);
    int k ;
    cin >> k ;
    rep(i , 1, k){
        int x, y;
        cin >> x >> y; 
        x++;
        y++;
        ed[x][y] = ed[y][x] = 1;
        tr[x].pb(y);
        tr[y].pb(x);
        
    }
    vector <int> az; 
    rep(i , 1, n){
        if(sz(tr[i]) > 1 || (k == 1 && sz(tr[i]) > 0)){
            az.pb(i);
        }
    }
    int MS= 0 , ans = -inf ;
    rep(ms , 0 ,(1<<sz(az))-1){
        rep(i , 1, n)ok[i] =1 ; 
        rep(j , 0 , sz(az)-1){
            int v = az[j] ;
            if(ms>>j&1){
                for(int x : tr[v])ok[x] = 0 ; 
            }else{
                ok[v] =0 ; 
            }
        }
        bool ok =0 ;
        rep(i , 0 ,sz(az)-1){
            rep(j , i+1 , sz(az)-1){
                if(ed[az[i]][az[j]]==1 && c(ms,i) && c(ms,j))ok =1 ; 
            }
        }
        if(ok)continue ;
        dfs(1) ;
        rep(ms2 , 0 , 15){
            if(sz(T[1]) == 1){
                if(!((c(ms2 , 0)&c(ms2 , 1)) || (c(ms2 , 0)&c(ms2,2)))){
                    if(ans < dp[vec[1].back()][ms2]){
                        ans = dp[vec[1].back()][ms2] ; 
                        MS = ms2 ;
                    }
                }

            }else{
                if(!(c(ms2 , 1)&c(ms2 ,2))){
                    if(ans < dp[vec[1].back()][ms2]){
                        ans = dp[vec[1].back()][ms2] ;
                        MS = ms2 ;
                    }
                }
            }
        }
    }
    rep(i , 1, n)ok[i] =1 ; 
    rep(j , 0 , sz(az)-1){
        int v = az[j] ;
        if(MS>>j&1){
            for(int x : tr[v])ok[x] = 0 ; 
        }else{
            ok[v] =0 ; 
        }
    }
    dfs(1) ;
    cp(1 , MS) ;
    cout << ans << " " << sz(A) << "\n";
    sort(all(A)) ;
    for(int x : A)cout << x-1<< " " ;
    cout << "\n" ;
    return 0;
}
/*
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3852kb

input:

6 7
1 1 1 1 1 1
0 1
1 2
2 3
2 4
1 5
1 4
0 5
1
2 5

output:

2 2
0 2 

result:

ok n=6, m=7, k=1, w=2

Test #2:

score: 0
Accepted
time: 1ms
memory: 3692kb

input:

2 1
2 5
0 1
1
0 1

output:

5 1
1 

result:

ok n=2, m=1, k=1, w=5

Test #3:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

3 3
1 1 2
1 2
0 1
0 2
1
1 2

output:

2 1
2 

result:

ok n=3, m=3, k=1, w=2

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3632kb

input:

4 4
2 3 2 4
0 2
1 3
2 3
0 3
1
2 3

output:

5 1
1 

result:

wrong answer The reported sum does not match the output set