이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(a) a.begin(),a.end()
#define mp make_pair
#define fi first
#define se second
const int maxn = (int)1e4+10;
int n, num=0;
int a[maxn], b[maxn], c[maxn], deg[maxn];
vector<int> adj[maxn];
bool vis[maxn];
void dfs(int s){
vis[s]=1; num++;
for(auto u : adj[s])
if(!vis[u]) dfs(u);
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n; int ans = 0;
for(int i = 0; i < n-1; i++) cin >> a[i] >> b[i] >> c[i];
for(int mask = 0; mask < (1<<(n-1)); mask++){
int sum = 0, ok=1;
for(int i = 1; i <= n; i++) adj[i].clear(), vis[i]=false, deg[i]=0;
for(int i = 0; i < n-1; i++) sum+=!!(mask&(1<<i))*c[i];
for(int i = 0; i < n-1; i++)
if(mask&(1<<i)) deg[a[i]]++, deg[b[i]]++, adj[a[i]].pb(b[i]);
for(int i = 1; i <= n; i++){
if(deg[i]>3) ok=0; num=0;
if(!vis[i]) dfs(i), ok&=(num%2==1);
}
if(ok) ans = max(ans, sum);
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
beads.cpp: In function 'int32_t main()':
beads.cpp:34:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
34 | if(deg[i]>3) ok=0; num=0;
| ^~
beads.cpp:34:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
34 | if(deg[i]>3) ok=0; num=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... |