제출 #334606

#제출 시각아이디문제언어결과실행 시간메모리
334606achibasadzishviliSjekira (COCI20_sjekira)C++14
110 / 110
84 ms14956 KiB
#include<bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back using namespace std; ll n,p[200005],mx[200005],ans; pair<ll,ll>a[200005]; vector<ll>v[200005]; ll find(ll x){ if(x == p[x])return x; return p[x] = find(p[x]); } void join(ll x,ll y){ x = find(x); y = find(y); if(x == y)return; ans += mx[x] + mx[y]; mx[x] = max(mx[x] , mx[y]); p[y] = x; } int main(){ ios::sync_with_stdio(false); cin >> n; for(int i=1; i<=n; i++){ p[i] = i; cin >> a[i].f; mx[i] = a[i].f; a[i].s = i; } for(int i=1; i<n; i++){ ll x,y; cin >> x >> y; if(a[x].f >= a[y].f) v[x].pb(y); if(a[y].f >= a[x].f) v[y].pb(x); } sort(a + 1 , a + n + 1); for(int o=1; o<=n; o++){ ll x = a[o].s; for(int i=0; i<v[x].size(); i++){ ll y = v[x][i]; join(x , y); } } cout << ans << '\n'; return 0; }

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

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