답안 #964011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964011 2024-04-16T07:46:06 Z 12345678 City Mapping (NOI18_citymapping) C++17
95.99 / 100
11 ms 1368 KB
#include "citymapping.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll nx=1e3+5;

ll ds[nx];
ll hv[nx], l[nx], sz[nx], rt, pa[nx], w[nx], t;
vector<pair<ll, ll>> k;
vector<ll> d[nx];
map<pair<ll, ll>, ll> mp;

ll dfssz(ll u)
{
    sz[u]=1;
    for (auto v:d[u]) sz[u]+=dfssz(v);
    if (d[u].size()==1) hv[u]=d[u][0], l[u]=-1;
    else if (d[u].size()==2)
    {
        if (sz[d[u][0]]<sz[d[u][1]]) swap(d[u][0], d[u][1]);
        hv[u]=d[u][0];
        l[u]=d[u][1];
    }  
    return sz[u];
}

ll query(ll u, ll v)
{
    if (u>v) swap(u, v);
    if (mp.find({u, v})!=mp.end()) return mp[{u, v}];
    return mp[{u, v}]=get_distance(u, v);
}

void find_roads(int N, int Q, int A[], int B[], int W[]) {
    pair<ll, ll> mx;
    for (ll i=2; i<=N; i++) mx=max(mx, {query(1, i), i});
    rt=mx.second;
    for (ll i=1; i<=N; i++) if (i!=rt) ds[i]=query(rt, i), k.push_back({ds[i], i});
    sort(k.begin(), k.end());
    for (auto [_, u]:k)
    {
        //prllf("here %d %d\n", rt, u);
        for (ll i=1; i<=N; i++) hv[i]=l[i]=-1;
        dfssz(rt);
        ll tmp=rt;
        while (1)
        {
            while (hv[tmp]!=-1) tmp=hv[tmp];
            ll ld=query(rt, tmp)-((query(rt, tmp)+query(rt, u))-query(u, tmp))/2;
            while (ld!=0) ld-=w[tmp], tmp=pa[tmp];
            if (d[tmp].size()<2)
            {
                d[tmp].push_back(u), pa[u]=tmp, w[u]=query(u, tmp), A[t]=u, B[t]=tmp, W[t++]=query(u, tmp);
                break;
            }
            else tmp=l[tmp];
        } 
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 860 KB Correct: 2991 out of 500000 queries used.
2 Correct 8 ms 856 KB Correct: 3737 out of 500000 queries used.
3 Correct 9 ms 856 KB Correct: 5893 out of 500000 queries used.
4 Correct 10 ms 1112 KB Correct: 7100 out of 500000 queries used.
5 Correct 9 ms 880 KB Correct: 3924 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 860 KB Correct: 2991 out of 500000 queries used.
2 Correct 8 ms 856 KB Correct: 3737 out of 500000 queries used.
3 Correct 9 ms 856 KB Correct: 5893 out of 500000 queries used.
4 Correct 10 ms 1112 KB Correct: 7100 out of 500000 queries used.
5 Correct 9 ms 880 KB Correct: 3924 out of 500000 queries used.
6 Correct 8 ms 1112 KB Correct: 2982 out of 500000 queries used.
7 Correct 11 ms 856 KB Correct: 3487 out of 500000 queries used.
8 Correct 8 ms 1128 KB Correct: 5757 out of 500000 queries used.
9 Correct 9 ms 1068 KB Correct: 6586 out of 500000 queries used.
10 Correct 10 ms 852 KB Correct: 3950 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 860 KB Correct: 2967 out of 12000 queries used.
2 Correct 10 ms 928 KB Correct: 2973 out of 12000 queries used.
3 Correct 8 ms 860 KB Correct: 2994 out of 12000 queries used.
4 Correct 8 ms 860 KB Correct: 2973 out of 12000 queries used.
5 Correct 8 ms 856 KB Correct: 2967 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 860 KB Correct: 2967 out of 12000 queries used.
2 Correct 10 ms 928 KB Correct: 2973 out of 12000 queries used.
3 Correct 8 ms 860 KB Correct: 2994 out of 12000 queries used.
4 Correct 8 ms 860 KB Correct: 2973 out of 12000 queries used.
5 Correct 8 ms 856 KB Correct: 2967 out of 12000 queries used.
6 Correct 8 ms 856 KB Correct: 2988 out of 12000 queries used.
7 Correct 8 ms 856 KB Correct: 2982 out of 12000 queries used.
8 Correct 8 ms 860 KB Correct: 2994 out of 12000 queries used.
9 Correct 8 ms 860 KB Correct: 2985 out of 12000 queries used.
10 Correct 9 ms 940 KB Correct: 2976 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 860 KB Correct: 2991 out of 500000 queries used.
2 Correct 8 ms 856 KB Correct: 3737 out of 500000 queries used.
3 Correct 9 ms 856 KB Correct: 5893 out of 500000 queries used.
4 Correct 10 ms 1112 KB Correct: 7100 out of 500000 queries used.
5 Correct 9 ms 880 KB Correct: 3924 out of 500000 queries used.
6 Correct 8 ms 1112 KB Correct: 2982 out of 500000 queries used.
7 Correct 11 ms 856 KB Correct: 3487 out of 500000 queries used.
8 Correct 8 ms 1128 KB Correct: 5757 out of 500000 queries used.
9 Correct 9 ms 1068 KB Correct: 6586 out of 500000 queries used.
10 Correct 10 ms 852 KB Correct: 3950 out of 500000 queries used.
11 Correct 9 ms 860 KB Correct: 2967 out of 12000 queries used.
12 Correct 10 ms 928 KB Correct: 2973 out of 12000 queries used.
13 Correct 8 ms 860 KB Correct: 2994 out of 12000 queries used.
14 Correct 8 ms 860 KB Correct: 2973 out of 12000 queries used.
15 Correct 8 ms 856 KB Correct: 2967 out of 12000 queries used.
16 Correct 8 ms 856 KB Correct: 2988 out of 12000 queries used.
17 Correct 8 ms 856 KB Correct: 2982 out of 12000 queries used.
18 Correct 8 ms 860 KB Correct: 2994 out of 12000 queries used.
19 Correct 8 ms 860 KB Correct: 2985 out of 12000 queries used.
20 Correct 9 ms 940 KB Correct: 2976 out of 12000 queries used.
21 Correct 10 ms 856 KB Correct: 2982 out of 25000 queries used.
22 Correct 8 ms 860 KB Correct: 3489 out of 25000 queries used.
23 Correct 9 ms 860 KB Correct: 3467 out of 25000 queries used.
24 Correct 8 ms 856 KB Correct: 3464 out of 25000 queries used.
25 Correct 8 ms 860 KB Correct: 5682 out of 25000 queries used.
26 Correct 10 ms 976 KB Correct: 5568 out of 25000 queries used.
27 Correct 8 ms 856 KB Correct: 5505 out of 25000 queries used.
28 Correct 8 ms 1052 KB Correct: 5792 out of 25000 queries used.
29 Correct 8 ms 1016 KB Correct: 5763 out of 25000 queries used.
30 Correct 10 ms 860 KB Correct: 5759 out of 25000 queries used.
31 Correct 9 ms 1116 KB Correct: 6651 out of 25000 queries used.
32 Correct 8 ms 856 KB Correct: 2979 out of 25000 queries used.
33 Correct 9 ms 1116 KB Correct: 6573 out of 25000 queries used.
34 Correct 9 ms 1112 KB Correct: 6644 out of 25000 queries used.
35 Correct 8 ms 1368 KB Correct: 6582 out of 25000 queries used.
36 Correct 11 ms 1116 KB Correct: 6646 out of 25000 queries used.
37 Correct 9 ms 1116 KB Correct: 6632 out of 25000 queries used.
38 Correct 9 ms 1016 KB Correct: 6650 out of 25000 queries used.
39 Correct 8 ms 1076 KB Correct: 6597 out of 25000 queries used.
40 Correct 9 ms 1116 KB Correct: 6685 out of 25000 queries used.
41 Correct 9 ms 1048 KB Correct: 6629 out of 25000 queries used.
42 Correct 11 ms 1112 KB Correct: 6632 out of 25000 queries used.
43 Correct 8 ms 860 KB Correct: 2988 out of 25000 queries used.
44 Correct 9 ms 1116 KB Correct: 6566 out of 25000 queries used.
45 Correct 8 ms 1116 KB Correct: 6585 out of 25000 queries used.
46 Correct 8 ms 1116 KB Correct: 6543 out of 25000 queries used.
47 Correct 9 ms 1052 KB Correct: 6638 out of 25000 queries used.
48 Correct 11 ms 1116 KB Correct: 6611 out of 25000 queries used.
49 Correct 9 ms 1116 KB Correct: 6599 out of 25000 queries used.
50 Correct 8 ms 1032 KB Correct: 6617 out of 25000 queries used.
51 Correct 9 ms 1096 KB Correct: 6608 out of 25000 queries used.
52 Correct 9 ms 1112 KB Correct: 6627 out of 25000 queries used.
53 Correct 9 ms 1116 KB Correct: 6627 out of 25000 queries used.
54 Correct 9 ms 856 KB Correct: 3492 out of 25000 queries used.
55 Correct 9 ms 1116 KB Correct: 6593 out of 25000 queries used.
56 Correct 9 ms 1112 KB Correct: 6596 out of 25000 queries used.
57 Correct 10 ms 1116 KB Correct: 6641 out of 25000 queries used.
58 Correct 9 ms 1076 KB Correct: 6595 out of 25000 queries used.
59 Correct 9 ms 1044 KB Correct: 6610 out of 25000 queries used.
60 Correct 8 ms 860 KB Correct: 3917 out of 25000 queries used.
61 Correct 9 ms 856 KB Correct: 3998 out of 25000 queries used.
62 Correct 9 ms 860 KB Correct: 3987 out of 25000 queries used.
63 Correct 9 ms 860 KB Correct: 3913 out of 25000 queries used.
64 Correct 9 ms 860 KB Correct: 3948 out of 25000 queries used.
65 Correct 8 ms 860 KB Correct: 3460 out of 25000 queries used.
66 Correct 9 ms 916 KB Correct: 3956 out of 25000 queries used.
67 Correct 8 ms 856 KB Correct: 3435 out of 25000 queries used.
68 Correct 10 ms 860 KB Correct: 3464 out of 25000 queries used.
69 Correct 8 ms 860 KB Correct: 3483 out of 25000 queries used.
70 Correct 8 ms 860 KB Correct: 3472 out of 25000 queries used.