# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
73835 |
2018-08-29T06:15:58 Z |
노영훈(#2275) |
통행료 (APIO13_toll) |
C++11 |
|
4 ms |
756 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int VMX=1010, EMX=5010;
int n, m, k, A[VMX];
vector<pii> G[VMX];
struct edge {
int u,v,c; bool greed=false;
void scan(){ cin>>u>>v>>c; }
bool operator < (const edge &e) const {
return c<e.c || (c==e.c || greed>e.greed);
}
} E[EMX], F[32];
int U[VMX];
int find(int x){ return x==U[x] ? x : U[x]=find(U[x]); }
void unite(int x, int y){ U[find(y)]=find(x); }
ll krusk(vector<edge> &W){
ll sum=0;
for(int i=1; i<=n; i++) G[i].clear(), U[i]=i;
sort(W.begin(), W.end());
for(edge &e:W){
int u=e.u, v=e.v, c=e.c;
if(find(u)==find(v)) continue;
unite(u,v); sum+=c;
if(e.greed) c=-c;
G[u].push_back({v,c});
G[v].push_back({u,c});
}
return sum;
}
pii par[VMX]; int dep[VMX];
void dfs1(int v=1, int p=-1, int d=0){
dep[v]=d;
for(pii e:G[v]){
int x,c; tie(x,c)=e; c=abs(c);
if(x==p) continue;
par[x]={v,c};
dfs1(x,v,d+1);
}
}
int lca_mx(int u, int v){
int res=0;
if(dep[u]<dep[v]) swap(u,v);
while(dep[u]>dep[v]) res=max(res, par[u].second), u=par[u].first;
while(u!=v){
res=max({res, par[u].second, par[v].second});
u=par[u].first, v=par[v].first;
}
return res;
}
ll sub[VMX];
ll dfs2(int v=1, int p=-1){
ll res=0; sub[v]=A[v];
for(pii e:G[v]){
int x,c; tie(x,c)=e;
if(x==p) continue;
res+=dfs2(x,v), sub[v]+=sub[x];
if(c<0) res+=abs(c)*sub[x];
}
return res;
}
ll check(int s){
vector<edge> W;
for(int i=1; i<=m; i++) W.push_back(E[i]);
for(int i=0; i<k; i++)
if(s&(1<<i)) W.push_back(F[i+1]);
krusk(W);
return dfs2();
}
void solve(){
vector<edge> W;
for(int i=1; i<=m; i++) W.push_back(E[i]);
krusk(W);
par[1]={-1,-1}; dfs1();
for(int i=1; i<=k; i++){
F[i].c = lca_mx(F[i].u, F[i].v);
}
ll ans=0;
for(int i=0; i<(1<<k); i++){
ans=max(ans, check(i));
}
cout<<ans<<'\n';
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>m>>k;
for(int i=1; i<=m; i++) E[i].scan();
for(int i=1; i<=k; i++) cin>>F[i].u>>F[i].v, F[i].greed=true;
for(int i=1; i<=n; i++) cin>>A[i];
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
756 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
756 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
756 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
756 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
756 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |