이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define sz(x) (ll)x.size()
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
void printVct(vi &v){
for (ll i =0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
vector <vi> arr, adj;
ll n;
vi con, hos, pro;
ll solve(ll k, vi v){
// dbg(i);
if (k >= n) return 0;
bool ok = true;
for (ll i=0; i<sz(v); i++){ //PROBLEM HERE => REUSED VARIABLE i!!!!!!!!!
for (ll j = 0; j<sz(adj[v[i]]); j++){
ll c = adj[v[i]][j];
if (c == k){
ok = false;
break;
}
}
if (!ok) break;
}
ll ans = solve(k+1, v);
if (ok){
vi new_v = v;
new_v.pb(k);
ans = max(ans, solve(k+1, new_v) + con[k]);
}
return ans;
}
// Find out best sample
int findSample(int N,int cc[],int hh[],int pp[]){
n = N;
for (ll i=0; i<n; i++){
con.pb(cc[i]);
hos.pb(hh[i]);
pro.pb(pp[i]);
}
adj.assign(n,vi());
for (ll i =1; i<n; i++){
ll c = hos[i];
if (pro[i] != 1){
adj[c].pb(i);
adj[i].pb(c);
}
if (pro[i] != 0){
for (ll j = 0; j<sz(adj[c]); j++){
ll d = adj[c][j];
adj[d].pb(i);
adj[i].pb(d);
}
}
}
arr.assign(n, vi(n,0));
for (ll i =0; i<n; i++){
for (ll j =0; j<sz(adj[i]); j++){
arr[i][j] = 1;
}
}
ll ans = solve(0, vi());
return ans;
}
/*
6
13 3 6 20 10 15
0 0 0 1 1 2 2 1 0 0
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |