QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#558282 | #8941. Even or Odd Spanning Tree | leafmaple# | WA | 1ms | 7600kb | C++20 | 1.2kb | 2024-09-11 15:18:15 | 2024-09-11 15:18:17 |
Judging History
answer
#include <bits/stdc++.h>
#define xs(a) cout<<setiosflags(ios::fixed)<<setprecision(a);
#define endl '\n'
using namespace std;
using ll = long long;
const int N=1e6+5;
#define int long long
array<int,2>a[N];
int w[N];
int n, res=-1e18;
int vis[N];
/*
*/
void dfs(int u, int ans){
int fk = 0;
for(int i=1; i<=n; i++)if(!vis[i])fk++;
if(!fk){
res = max(res, ans);
return ;
}
if(u == 0){
for(int i=1; i<=n; i++)if(!vis[i])return ;
res = max(res, ans);
return ;
}
dfs(u-1, ans);
int cnt = 0;
vector<int>v;
for(int i=1; i<=n && cnt < u; i++)if(!vis[i]){
if(a[i][0] <= u && a[i][1] >= u ){
cnt ++;
v.push_back(i);
}
}
if(cnt == u){
for(auto x: v)vis[x] = 1;
dfs(u, ans + w[u]);
for(auto x: v)vis[x] = 0;
}
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i=1; i<=n; i++) cin >> a[i][0] >> a[i][1];
sort(a+1, a+1+n, greater<array<int,2>>());
// sort(a+1, a+1+n);
for(int i=1; i<=n; i++) cin >> w[i];
dfs(n, 0);
if(res == -1e18) cout << "impossible" << endl;
else cout << res << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7600kb
input:
3 2 1 1 2 5 3 1 1 3 1 4 4 1 2 1 1 3 1 1 4 1 2 4 2
output:
impossible
result:
wrong output format Expected integer, but "impossible" found