# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1011519 | 2024-06-30T14:48:12 Z | pcc | Telegraph (JOI16_telegraph) | C++17 | 0 ms | 348 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define fs first #define sc second #define pll pair<ll,ll> const int mxn = 1e5+10; pii arr[mxn]; int deg[mxn]; queue<int> q; int N; ll dp[mxn][2]; ll sum = 0; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N; for(int i = 1;i<=N;i++){ cin>>arr[i].fs>>arr[i].sc; sum += arr[i].sc; deg[arr[i].fs]++; } for(int i = 1;i<=N;i++)if(!deg[i])q.push(i); while(!q.empty()){ auto now = q.front(); q.pop(); auto [nxt,d] = arr[now]; deg[nxt]--; dp[nxt][0] = max(dp[nxt][0],max(dp[now][0],dp[now][1])); dp[nxt][1] = max(dp[nxt][1],max(dp[now][0],dp[now][1])+d); if(!deg[nxt])q.push(nxt); } ll ans = 0; for(int ii = 1;ii<=N;ii++){ if(!deg[ii])continue; int now = ii; vector<pii> v; priority_queue<ll,vector<ll>,less<ll>> pq; do{ deg[now] = 0; auto [nxt,d] = arr[now]; pq.push(dp[nxt][1]-dp[nxt][0]-d); ans += dp[nxt][0]+d; now = nxt; }while(now != ii); if(pq.size() == N)continue; ans += pq.top();pq.pop(); while(!pq.empty()&&pq.top()>0){ ans += pq.top(); pq.pop(); } } cout<<sum-ans<<'\n'; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |