제출 #434855

#제출 시각아이디문제언어결과실행 시간메모리
434855cpp219구슬과 끈 (APIO14_beads)C++14
28 / 100
1 ms484 KiB
#pragma GCC optimization O2 #pragma GCC optimization "unroll-loop" #pragma target ("avx2") #include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; typedef pair<ll,ll> LL; const ll N = 1e3 + 9; const ll inf = 1e9 + 7; vector<LL> g[N]; ll n,x,y,w,dp[N][2],All[N],ans; void DFS(ll u,ll p){ ll child = 0; for (auto i : g[u]) if (i.fs != p) DFS(i.fs,u),child++; dp[u][0] = dp[u][1] = 0; if (!child) dp[u][1] = -inf; for (auto i : g[u]){ ll v = i.fs,cost = i.sc; if (v == p) continue; dp[u][0] += max(dp[v][1] + cost,dp[v][0]); All[u] += dp[v][1]; } for (auto i : g[u]){ ll v = i.fs,cost = i.sc; if (v == p) continue; ll now = dp[u][0] - max(dp[v][1] + cost,dp[v][0]) + dp[v][0] + cost; dp[u][1] = max(dp[u][1],now); } } int main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "tst" if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } cin>>n; for (ll i = 1;i < n;i++){ cin>>x>>y>>w; g[x].push_back({y,w}); g[y].push_back({x,w}); } for (ll i = 1;i <= n;i++){ DFS(i,0); ans = max(ans,dp[i][0]); //cout<<dp[i][0]; return 0; } cout<<ans; }

컴파일 시 표준 에러 (stderr) 메시지

beads.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization O2
      | 
beads.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
beads.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    3 | #pragma target ("avx2")
      | 
beads.cpp: In function 'int main()':
beads.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...