QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#189250 | #5102. Dungeon Crawler | bulijiojiodibuliduo# | WA | 1ms | 4420kb | C++17 | 1.9kb | 2023-09-27 04:42:06 | 2023-09-27 04:42:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=2010,M=201000;
ll g[N][N],te,ret[M],d[N];
int n,q,par[N],pw[N],pe[N];
VI ord;
vector<PII> e[N];
vector<array<int,3>> qr[N];
void dfs0(int u,int f,ll d,int rt) {
g[rt][u]=d;
for (auto [v,w]:e[u]) if (v!=f) {
dfs0(v,u,d+w,rt);
}
}
void gao(int u,int f) {
ord.pb(u);
for (auto [v,w]:e[u]) if (v!=f) {
par[v]=u;
pw[v]=w;
gao(v,u);
}
}
int main() {
scanf("%d%d",&n,&q);
rep(i,1,n) {
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
e[u].pb(mp(v,w));
e[v].pb(mp(u,w));
te+=w;
}
rep(i,1,n+1) dfs0(i,0,0,i);
rep(i,0,q) {
int s,k,t;
scanf("%d%d%d",&s,&k,&t);
ret[i]=-1;
if (g[s][t]+g[t][k]==g[s][k]) {
continue;
}
qr[s].pb({k,t,i});
}
rep(rt,1,n+1) {
ord.clear();
gao(rt,0);
par[rt]=0;
pw[rt]=0;
d[rt]=0;
for (auto [k,t,id]:qr[rt]) {
rep(i,1,n+1) pe[i]=pw[i];
int u=k;
while (g[rt][u]+g[u][t]!=g[rt][t]) {
pe[u]=0;
u=par[u];
}
ll ans=0;
rep(i,1,SZ(ord)) {
int u=ord[i];
d[u]=d[par[u]]+pe[u];
ans=max(ans,d[u]);
}
ret[id]=2*te-ans;
}
}
rep(i,0,q) {
if (ret[i]==-1) puts("impossible");
else printf("%lld\n",ret[i]);
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3920kb
input:
22 5 1 2 7 2 3 5 3 4 8 3 6 6 3 7 3 2 5 6 5 8 2 8 9 11 2 10 16 1 11 12 11 12 4 11 13 9 1 14 25 14 15 4 15 16 5 15 17 6 15 18 1 15 19 8 14 20 7 20 21 9 20 22 17 1 19 9 1 9 19 1 8 9 1 9 8 2 22 11
output:
316 293 293 impossible 314
result:
ok 5 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 4420kb
input:
100 100 1 2 289384 2 3 930887 2 4 692778 4 5 636916 4 6 747794 4 7 238336 4 8 885387 8 9 760493 8 10 516650 8 11 641422 8 12 202363 8 13 490028 8 14 368691 8 15 520060 8 16 897764 16 17 513927 16 18 180541 16 19 383427 16 20 89173 16 21 455737 16 22 5212 16 23 595369 16 24 702568 16 25 956430 16 26 ...
output:
103526917 103484292 106288816 104379596 104405611 104775512 104920752 105291604 103838430 104473606 104200895 104175650 105851068 104509242 103971939 105376499 105223283 104153426 105082245 104899258 104130613 104800548 106846555 104138329 103769253 104465739 104044745 104385328 105464621 105460460 ...
result:
wrong answer 7th lines differ - expected: '105434682', found: '104920752'