QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#769730 | #6342. Security Guard | 275307894a | 0 | 3ms | 7124kb | C++14 | 1.7kb | 2024-11-21 19:10:10 | 2024-11-21 19:10:10 |
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e5+5,M=N*4+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n,m,Q,A[N],id[N];
vector<int> S[N];
int fa[N];
ll w[N];
int GF(int x){
if(x==fa[x]) return x;
int v=GF(fa[x]);
w[x]+=w[fa[x]];
return fa[x]=v;
}
void Solve(){
scanf("%d%d%d",&n,&m,&Q);
for(int i=1;i<=n;i++) scanf("%d",&A[i]);
ll ans=0;
while(m--){
int x,y;scanf("%d%d",&x,&y);
S[x].push_back(y);S[y].push_back(x);
ans+=min(A[x],A[y]);
}
iota(fa+1,fa+n+1,1);
iota(id+1,id+n+1,1);
for(int i=1;i<=n;i++){
int x=id[i];
for(int j:S[x]) if(A[j]<A[x]){
int v=GF(j);
ll res=A[i]-A[j]-(w[j]+w[v]);
ans+=max(res,0ll);w[v]+=max(res,0ll);w[i]+=max(-res,0ll);
fa[v]=i;
}
}
printf("%lld\n",ans);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 7124kb
input:
200000 199999 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
1
result:
wrong answer 1st numbers differ - expected: '199999', found: '1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #85:
score: 0
Wrong Answer
time: 1ms
memory: 6408kb
input:
16 15 200000 692461146 622302385 805066691 422290641 600839873 940930580 873147413 489653843 239129952 383473127 21389393 913787109 856138328 859082963 262475462 327598064 6 13 6 9 6 15 6 14 6 16 6 8 5 6 1 6 4 6 3 6 6 11 6 7 6 10 2 6 6 12
output:
14113958700
result:
wrong answer Answer contains longer sequence [length = 200001], but output contains 1 elements
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%