| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 199314 | kshitij_sodani | Paprike (COI18_paprike) | C++17 | 10 ms | 632 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int llo ;
#define mp make_pair
#define pb push_back
#define a first
#define b second
vector<llo> adj[16];
vector<pair<llo,llo>> ed;
vector<llo> adj2[16];
llo it[16];
llo vis[16];
llo ans;
vector<llo> stac;
llo n,k;
llo co;
void dfs(llo no){
co+=it[no];
for(llo j=0;j<adj2[no].size();j++){
llo nn=adj2[no][j];
if(vis[nn]==0){
vis[nn]=1;
dfs(nn);
}
}
}
void recurse(llo ind){
if(ind==n-1){
llo tot=n-1;
for(llo i=0;i<stac.size();i++){
if(stac[i]==1){
tot-=1;
adj2[ed[i].a].pb(ed[i].b);
adj2[ed[i].b].pb(ed[i].a);
}
}
llo st=1;
memset(vis,0,sizeof(vis));
for(llo i=0;i<n;i++){
if(vis[i]==0){
co=0;
vis[i]=1;
dfs(i);
if(co>k){
st=0;
}
}
}
if(st==1){
ans=min(ans,tot);
}
for(llo i=0;i<n;i++){
adj2[i].clear();
}
}
else{
stac.pb(1);
recurse(ind+1);
stac.pop_back();
stac.pb(0);
recurse(ind+1);
stac.pop_back();
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>k;
ans=n-1;
for(llo i=0;i<n;i++){
cin>>it[i];
}
llo aa,bb;
for(llo i=0;i<n-1;i++){
cin>>aa>>bb;
adj[aa-1].pb(bb-1);
adj[bb-1].pb(aa-1);
ed.pb(mp(aa-1,bb-1));
}
recurse(0);
cout<<ans<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
