QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#502010 | #125. Wild Boar | Rafi22 | 0 | 10ms | 8748kb | C++20 | 4.2kb | 2024-08-03 00:29:17 | 2024-08-03 00:29:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define ROF(i,r,l) for(int i=(r);i>=(l);i--)
int inf=1000000007;
ll infl=1000000000000000007;
ll mod=1000000007;
const int N=2007,pot=1<<17;
vector<pair<pair<int,int>,ll>>Merge(vector<pair<pair<int,int>,ll>>L,vector<pair<pair<int,int>,ll>>R)
{
if(sz(R)==0) return L;
vector<pair<pair<int,int>,ll>>ans;
int a,b;
ll mn=infl;
vector<pair<int,int>>xd;
for(auto [pl,cl]:L)
{
for(auto [pr,cr]:R)
{
if(pl.nd!=pr.st&&cl+cr<mn)
{
mn=cl+cr;
a=pl.st;
b=pr.nd;
}
}
}
if(mn!=infl)
{
ans.pb({{a,b},mn});
xd.pb({a,b});
}
auto add=[&](int xa,int ya)
{
int x,y;
mn=infl;
for(auto [pl,cl]:L)
{
for(auto [pr,cr]:R)
{
bool nie=0;
for(auto [xx,yy]:xd) if(pl.st==xx&&pr.nd==yy) nie=1;
if(nie) continue;
if(pl.st!=xa&&pr.nd!=ya&&pl.nd!=pr.st&&cl+cr<mn)
{
mn=cl+cr;
x=pl.st;
y=pr.nd;
}
}
}
if(mn!=infl)
{
ans.pb({{x,y},mn});
xd.pb({x,y});
}
};
add(a,-1);
add(-1,b);
add(a,b);
return ans;
}
vector<pair<pair<int,int>,ll>>seg[2*pot+7];
vector<pair<pair<int,int>,ll>>T[N][N];
ll g[N][N];
vector<pair<int,ll>>G[N];
int X[pot];
vector<pair<ll,int>>d[N][N];
ll dis[N][N];
void upd(int v)
{
v+=pot-1;
while(v>1)
{
v/=2;
seg[v]=Merge(seg[2*v],seg[2*v+1]);
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m,q,L;
cin>>n>>m>>q>>L;
FOR(i,1,m)
{
int a,b,c;
cin>>a>>b>>c;
g[a][b]=c;
g[b][a]=c;
G[a].pb({b,c});
G[b].pb({a,c});
}
FOR(i,1,n)
{
for(auto [j,c1]:G[i])
{
priority_queue<pair<ll,pair<int,int>>>Q;
Q.push({0,{j,i}});
FOR(l,1,n) d[j][l].clear();
while(sz(Q)>0)
{
ll D=-Q.top().st;
int v=Q.top().nd.st,o=Q.top().nd.nd;
Q.pop();
if(sz(d[j][v])>=2||(sz(d[j][v])==1&&d[j][v][0].nd==o)) continue;
d[j][v].pb({D,o});
for(auto [u,c]:G[v]) if(v!=j||u!=i) Q.push({-(D+c),{u,v}});
}
}
FOR(j,1,n)
{
if(i==j) continue;
int a,b;
ll mn=infl;
if(g[i][j])
{
a=j,b=i;
mn=g[i][j];
}
vector<pair<int,int>>xd;
for(auto [A,ca]:G[i])
{
for(auto [B,cb]:G[j])
{
dis[A][B]=infl;
debug(i,j,A,B,sz(d[A][B]));
if(sz(d[A][B])>0&&d[A][B][0].nd!=j) dis[A][B]=d[A][B][0].st;
else if(sz(d[A][B])>1) dis[A][B]=d[A][B][1].st;
if(ca+dis[A][B]+cb<mn)
{
mn=ca+dis[A][B]+cb;
a=A;
b=B;
}
}
}
if(mn!=infl)
{
T[i][j].pb({{a,b},mn});
xd.pb({a,b});
}
auto add = [&](int xa,int ya)
{
mn=infl;
int x,y;
for(auto [A,ca]:G[i])
{
if(A==xa) continue;
for(auto [B,cb]:G[j])
{
if(B==ya) continue;
bool nie=0;
for(auto [xx,yy]:xd) if(A==xx&&B==yy) nie=1;
if(nie) continue;
if(ca+dis[A][B]+cb<mn)
{
mn=ca+dis[A][B]+cb;
x=A;
y=B;
}
}
}
if(mn!=infl)
{
T[i][j].pb({{x,y},mn});
xd.pb({x,y});
}
};
add(a,-1);
add(-1,b);
add(a,b);
}
}
FOR(i,1,L) cin>>X[i];
FOR(i,1,L-1)
{
seg[i+pot-1]=T[X[i]][X[i+1]];
debug(seg[i+pot-1]);
}
ROF(i,pot-1,1) seg[i]=Merge(seg[2*i],seg[2*i+1]);
debug(seg[1]);
while(q--)
{
int i;
cin>>i>>X[i];
if(i>1)
{
seg[i-1+pot-1]=T[X[i-1]][X[i]];
debug(T[X[i-1]][X[i]]);
upd(i-1);
}
if(i<L)
{
seg[i+pot-1]=T[X[i]][X[i+1]];
debug(T[X[i]][X[i+1]]);
upd(i);
}
ll ans=infl;
for(auto [p,x]:seg[1]) ans=min(ans,x);
if(ans==infl) cout<<-1<<endl;
else cout<<ans<<endl;
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 10ms
memory: 8748kb
input:
5 5 1 10 1 4 10 2 4 2 2 5 4 3 5 4 4 5 7 2 4 5 3 5 3 5 4 2 1 10 1
output:
29
result:
wrong answer 1st lines differ - expected: '-1', found: '29'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%