Submission #958319

#TimeUsernameProblemLanguageResultExecution timeMemory
958319moonrabbit2초대 (JOI12_invitation)C++17
30 / 100
128 ms131072 KiB
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma") #include <bits/stdc++.h> using namespace std; using ll=long long; using pii=array<int,2>; using tii=array<int,3>; #ifdef LOCAL #include "debug.h" #else #define debug(...) #endif const int N=2005; int n,m,s,k,p[N]; vector<tii> E; ll ans; int Find(int x){ if(!p[x]) return x; return p[x]=Find(p[x]); } bool Union(int x,int y){ x=Find(x); y=Find(y); if(x==y) return false; p[y]=x; return true; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>n>>m>>s>>k; for(int l,r,s,e,c,i=1;i<=k;i++){ cin>>l>>r>>s>>e>>c; for(int j=l;j<r;j++) E.push_back({c,j,j+1}); for(int j=s;j<e;j++) E.push_back({c,n+j,n+j+1}); E.push_back({c,l,n+s}); } sort(E.begin(),E.end(),greater<>()); for(auto [c,u,v]: E) if(Union(u,v)) ans+=c; for(int i=2;i<=n+m;i++) if(Find(1)!=Find(i)){ cout<<"-1\n"; return 0; } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...