제출 #328087

#제출 시각아이디문제언어결과실행 시간메모리
328087model_codeSjekira (COCI20_sjekira)C++17
110 / 110
64 ms3936 KiB
#include <cstdio> #include <algorithm> #include <vector> using namespace std; const int MAXN = 100005; typedef pair<int,int> ii; int n; int t[MAXN]; vector<ii> e; int uf[MAXN], mv[MAXN]; bool cmp(const ii& a, const ii& b) { int x = max(t[a.first], t[a.second]); int y = max(t[b.first], t[b.second]); return x<y; } int fnd(int x){ if(x==uf[x]) return x; else return uf[x]=fnd(uf[x]); } long long sol = 0; void un(int x, int y){ x = fnd(x); y = fnd(y); if(x != y){ sol += mv[x] + mv[y]; mv[y] = max(mv[y], mv[x]); uf[x] = y; } } int main(){ scanf("%d", &n); for(int i=0;i<n;i++){ scanf("%d", &t[i]); uf[i] = i; mv[i] = t[i]; } for(int i=1;i<n;i++){ int u,v; scanf("%d%d", &u, &v); e.push_back(ii(u-1, v-1)); } sort(e.begin(), e.end(), cmp); for(auto i:e){ un(i.first, i.second); } printf("%lld\n", sol); }

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

sjekira.cpp: In function 'int main()':
sjekira.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
sjekira.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |         scanf("%d", &t[i]);
      |         ~~~~~^~~~~~~~~~~~~
sjekira.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...