제출 #793078

#제출 시각아이디문제언어결과실행 시간메모리
7930781075508020060209tcSjekira (COCI20_sjekira)C++14
0 / 110
82 ms20328 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n; int ar[500005]; vector<int>e[500005]; int uf[500005]; int umx[500005]; int fin(int x){ if(uf[x]==x){return x;} uf[x]=fin(uf[x]); return uf[x]; } void mrg(int a,int b){ int pa=fin(a);int pb=fin(b); if(pa==pb){return;} uf[pa]=pb; umx[pb]=max(umx[pa],umx[pb]); } signed main() { cin>>n; for(int i=1;i<=n;i++){ cin>>ar[i]; uf[i]=i; umx[i]=ar[i]; } for(int i=1;i<=n-1;i++){ int a;int b; cin>>a>>b; e[a].push_back(b); e[b].push_back(a); } int ans=0; vector<pair<int,int>>seq; for(int i=1;i<=n;i++){ seq.push_back({ar[i],i}); } //cout<<"hihi"; sort(seq.begin(),seq.end()); for(int i=0;i<seq.size();i++){ int nw=seq[i].second; for(int j=0;j<e[nw].size();j++){ int v=e[nw][j]; if(fin(v)==fin(nw)){continue;} ans+=umx[fin(v)]+umx[fin(nw)]; mrg(v,nw); } } cout<<ans<<endl; return 0; }

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

sjekira.cpp: In function 'int main()':
sjekira.cpp:42:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i=0;i<seq.size();i++){
      |                 ~^~~~~~~~~~~
sjekira.cpp:44:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for(int j=0;j<e[nw].size();j++){
      |                     ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...