QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784950 | #6660. 택시 여행 | jiamengtong | 0 | 1108ms | 106424kb | C++14 | 3.6kb | 2024-11-26 16:24:49 | 2024-11-26 16:24:50 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define M 100005
using namespace std;
const ll V = 1e12;
vector<pair<ll, ll> > v[M], F[M];
ll vis[M], sz[M], maxsz[M], minn, nrt, tot;
void dfs1(int x, int fa, int dep, int rt)
{
F[x].push_back({rt, dep});
for(auto t : v[x]) if(!vis[t.first] && t.first != fa) dfs1(t.first, x, dep + t.second, rt);
}
void dfs2(int x, int fa)
{
sz[x] = 1;
maxsz[x] = 0;
for(auto t : v[x]) if(!vis[t.first] && t.first != fa)
{
dfs2(t.first, x);
sz[x] += sz[t.first];
maxsz[x] = max(maxsz[x], sz[t.first]);
}
// cout << x << " " << tot << " " << sz[x] << " " << maxsz [ x ] << endl ;
maxsz[x] = max(maxsz[x], tot - sz[x]);
if(maxsz[x] < minn) minn = maxsz[x], nrt = x;
}
void csz(int x, int fa)
{
sz[x] = 1;
for(auto t : v[x]) if(!vis[t.first] && t.first != fa)
{
csz(t.first, x);
sz[x] += sz[t.first];
}
}
void dfs(ll x)
{
cout << x << endl;
vis[x] = 1;
dfs1(x, -1, 0, x);
for(auto t : v[x])
{
if(vis[t.first]) continue;
minn = 1e9;
nrt = -1;
tot = sz[t.first];
dfs2(t.first, -1);
csz(nrt, -1);
// cout << nrt << endl;
dfs(nrt);
}
}
struct Line{
ll k, b;
ll gt(ll x)
{
return x * k + b;
}
}tr[M << 5];
ll ls[M << 5], rs[M << 5], root[M], num;
void Insert(ll &p, ll l, ll r, Line x)
{
if(!p)
{
tr[p = ++num] = x;
return;
}
if(l == r) return;
ll mid = (l + r) >> 1ll;
// cout << "INS: " << x.k << " " << x.b << " " << tr[p].k << " " << tr[p].b << endl;
if(x.gt(mid) < tr[p].gt(mid)) swap(x, tr[p]);
// cout << "INS: " << x.k << " " << x.b << " " << tr[p].k << " " << tr[p].b << endl;
if(x.k < tr[p].k) Insert(rs[p], mid + 1, r, x);// cout << "GTR: " << rs[p] << '\n';
else Insert(ls[p], l, mid, x);// cout << "GTL: " << p << " " << ls[p] << '\n';
}
ll qry(ll p, ll l, ll r, ll x)
{
if(!p) return 1e18;
ll mid = (l + r) >> 1ll;
ll res = tr[p].gt(x);
// cout << p << " " << tr[p].k << " " << tr[p].b << " " << res << " " << x << endl;
if(x <= mid) res = min(res, qry(ls[p], l, mid, x));// cout << "GTL: " << p << " " << ls[p] << '\n';
else res = min(res, qry(rs[p], mid + 1, r, x));// cout << "GTR: " << rs[p] << '\n';
return res;
}
void update(int x, Line y)
{
for(auto t : F[x]) Insert(root[t.first], 0, V, {y.k, y.b + t.second * y.k});// cout << x << " " << t.first << endl;
}
ll query(int x)
{
ll ans = 1e18;
for(auto t : F[x]) ans = min(ans, qry(root[t.first], 0, V, t.second));// cout << t.first << " " << x << " " << t.second << " " << qry(root[t.first], 0, V, t.second) << endl;
return ans;
}
std::vector<long long> travel(std::vector<long long> A, std::vector<int> B, std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
int n = A.size();
for(ll i = 0; i < n - 1; i++) v[U[i]].push_back({V[i], W[i]}), v[V[i]].push_back({U[i], W[i]});
csz(0, -1);
dfs(0);
vector<int> id(n);
iota(id.begin(), id.end(), 0);
sort(id.begin(), id.end(), [&](int x, int y){return B[x] > B[y];});
for(auto t : id)
{
ll ndis = (t == 0 ? 0 : query(t));
// cout << t << " " << ndis << " " << query(t) << '\n';
update(t, {B[t], A[t] + ndis});
}
vector<ll> res(n - 1);
for(int i = 1; i < n; i++) res[i - 1] = query(i);
return res;
}
//signed main()
//{
// int n;
// scanf("%d", &n);
// vector<ll> A;
// vector<int> B, U, V, W;
// for(int i = 1, x; i <= n; i++) scanf("%d", &x), A.push_back(x);
// for(int i = 1, x; i <= n; i++) scanf("%d", &x), B.push_back(x);
// for(int i = 1, x, y, z; i < n; i++) scanf("%d%d%d", &x, &y, &z), U.push_back(x), V.push_back(y), W.push_back(z);
// vector<ll> res = travel(A, B, U, V, W);
// for(int i = 0; i < n - 1; i++) printf("%d ", res[i]);
// puts("");
// return 0;
//}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 14396kb
input:
2 684124582850 713748627948 74361 256955 0 1 661088
output:
Unauthorized output
result:
wrong answer 1st lines differ - expected: 'secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I', found: 'Unauthorized output'
Subtask #2:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 1108ms
memory: 106424kb
input:
100000 746699125678 374834842799 250803643493 620187038832 454433387570 406226564003 897157438699 99473514061 734784419618 503968957100 363935477037 277126009840 52078020050 990757079812 847235285349 950784717285 271017141367 861087225700 996035427219 520682200664 282013988419 415183977876 882007771...
output:
Unauthorized output
result:
wrong answer 1st lines differ - expected: 'secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I', found: 'Unauthorized output'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Wrong Answer
Test #69:
score: 0
Wrong Answer
time: 259ms
memory: 41240kb
input:
100000 15175010 23519365 21177669 27079342 9089 16784452 29693960 23124925 17048604 10179491 12828214 24992902 8483134 2928073 23807522 7332137 17421520 28460746 1607282 13224363 11900728 11794692 11495061 4687109 23460275 7657982 27417256 16978162 7326803 23083826 24942987 16610314 12147303 2828271...
output:
Unauthorized output
result:
wrong answer 1st lines differ - expected: 'secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I', found: 'Unauthorized output'
Subtask #5:
score: 0
Wrong Answer
Test #94:
score: 0
Wrong Answer
time: 218ms
memory: 39332kb
input:
99281 551670361798 568902251563 418071776626 697635341894 641578820039 117221079324 812766431051 425410617978 663769685693 282144284527 799662290178 749088952784 586626406385 122473825417 459510657357 871705247919 443707710712 735612808044 237919555727 829939639783 122127143240 616906466299 24431898...
output:
Unauthorized output
result:
wrong answer 1st lines differ - expected: 'secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I', found: 'Unauthorized output'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%