제출 #332601

#제출 시각아이디문제언어결과실행 시간메모리
332601souvenir_vayneSjekira (COCI20_sjekira)C++14
110 / 110
56 ms7148 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <chrono> #define pb push_back #define INF 0x3f3f3f3f //#define LINF 0x3f3f3f3f3f3f3f3f //#define endl '\n' #define ll long long #define f first #define int long long #define fin cin #define fout cout #define s second #define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0) #define debug(x) cout << "DEBUG " << x << endl #define debug2(x, y) cout << "DEBUG " << x << " " << y << endl #define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl #define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl #define all(x) x.begin(), x.end() #define left vadia #define lb lower_bound #define right puta using namespace std; using namespace __gnu_pbds; void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str( ),"w",stdout); } typedef pair<ll, ll> pii; typedef vector<vector<char>> mat; typedef pair<int, string> pis; const ll mod = 1e9+7; typedef vector<int> vi; typedef pair<int, pair<int, int>> piii; const int MAXN = 1e5+5; int p[MAXN], pai[MAXN]; bool cmp(pii a, pii b) { return max(p[a.f], p[a.s]) < max(p[b.f], p[b.s]); } int ans = 0; int find(int x) { if(pai[x] == x) return x; else return pai[x] = find(pai[x]); } void query(int a, int b) { a = find(a), b = find(b); if(a != b) { if(p[a] < p[b]) swap(a, b); ans += p[a] + p[b]; pai[b] = a; } } int32_t main() { FAST; int n; cin >> n; for(int i = 1; i <= n; i++) { cin >> p[i]; pai[i] = i; } vector<pii> e(n-1); for(pii &i : e) cin >> i.f >> i.s; sort(all(e), cmp); for(pii &i : e) query(i.f, i.s); cout << ans << endl; }

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

sjekira.cpp: In function 'void setIO(std::string)':
sjekira.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   27 |   freopen((s+".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sjekira.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   28 |   freopen((s+".out").c_str( ),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...