QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#797983#7600. Minimums on the EdgesCookie_CreammWA 4ms8400kbC++232.6kb2024-12-03 22:25:082024-12-03 22:25:09

Judging History

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

  • [2024-12-03 22:25:09]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:8400kb
  • [2024-12-03 22:25:08]
  • 提交

answer

#include<bits/stdc++.h>


using namespace std;
#define ll long long
#define vt vector
#define pb push_back
#define pii pair<int, int>
#define sz(dq) (int)dq.size()
#define forr(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pll pair<ll, ll>
#define mpp make_pair
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ld long double

const ll mxn = 4e5 + 5, inf = 1e9, mod = 998244353, sq = 800, mxv = 1e6 + 5, pr = 37, mod2 = 1e9 + 9, mod3 = 998244353;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, s;
int cnt[(1 << 18)], dp[(1 << 18)][105];
pii trace[(1 << 18)][105];
int res[19];
bool ckmax(int &a, int b){
    if(a < b){
        a = b; return(1);
    }
    return(0);
}
void solve(){       
    cin >> n >> m >> s;
    for(int i = 0; i < m; i++){
        int u, v; cin >> u >> v; --u; --v;
        cnt[(1 << u) | (1 << v)] = 1;
    }
    for(int i = 0; i < 18; i++){
        for(int j = 0; j < (1 << 18); j++){
            if((j >> i) & 1){
                cnt[j] += cnt[j ^ (1 << i)];
            }
        }
    }
    for(int i = 0; i < (1 << n); i++){
        for(int j = 0; j <= s; j++){
            dp[i][j] = -inf;
        }
    }
    dp[0][0] = 0;
    for(int i = 0; i < (1 <<  n); i++){
        int c = __builtin_popcount(i);
        for(int j = 0; j <= s; j++){
            if(dp[i][j] == -inf)continue;
            for(int k = 0; k < n; k++){
                if(!((i >> k) & 1)){
                    if(ckmax(dp[i | (1 << k)][j], dp[i][j])){
                        trace[i | (1 << k)][j] = mpp(i, j);
                    }
                }
            }
            if(j + c <= s){
                if(ckmax(dp[i][j + c], dp[i][j] + cnt[i])){
                    trace[i][j + c] = mpp(i, j);
                }
            }
        }  
    }
    pii state;
    int ans = -1;
    for(int i = 0; i <= s; i++){
        if(ckmax(ans, dp[(1 << n) - 1][i])){
            state = mpp((1 << n) - 1, i);
        }
    }
    while(state.fi != 0){
        pii cool = trace[state.fi][state.se];
        if(state.se != cool.se){
            for(int i = 0; i < n; i++){
                if((cool.fi >> i) & 1)res[i]++;
            }
        }
        state = cool;
    }
    for(int i = 0; i < n; i++)cout << res[i] <<  " ";
}
 
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("ARRAY.inp", "r", stdin);
    //freopen("ARRAY.out", "w", stdout);
    
    int tt; tt = 1;
    while(tt--){
        solve();
    }
    return(0);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 4 6
1 2
2 3
3 1
1 4

output:

2 2 2 0 

result:

ok answer = 6

Test #2:

score: -100
Wrong Answer
time: 4ms
memory: 6904kb

input:

3 7 7
1 2
1 2
1 2
1 3
1 3
2 3
2 3

output:

2 2 2 

result:

wrong answer sum of values isn't equal to s (s = 7)