# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
748068 | 2023-05-25T10:57:51 Z | onebit1024 | City Mapping (NOI18_citymapping) | C++17 | 243 ms | 928 KB |
#include "citymapping.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define all(c) c.begin(), c.end() #define endl "\n" const double PI=3.141592653589; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " <<"[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif vector<int>sub,in,out; vector<vector<int>>adj; int t = 1; void comp(int u, int p,set<ll>&active){ sub[u] = 1; in[u] = t++; for(int v : adj[u]){ if(v==p || !active.count(v))continue; comp(v,u,active); sub[u]+=sub[v]; } out[u] = t++; } bool above(int u, int v){ if(u==v)return 1; return in[u] < in[v] && out[u] > out[v]; } void find_roads(int n, int Q, int a[], int b[], int w[]) { vector<pair<ll,ll>>k; vector<ll>dist1(n+1); for(int i = 2;i<=n;++i)dist1[i] = get_distance(1,i); for(int i = 2;i<=n;++i)k.pb({dist1[i],i}); sort(all(k)); adj.resize(n+1); sub.resize(n+1); in.resize(n+1); out.resize(n+1); set<ll>active = {1}; int p = 0; for(int i = 0;i<k.size();++i){ int prev = 1; while(active.size()>1){ sub = vector<int>(n+1); in = vector<int>(n+1); out = vector<int>(n+1); t = 1; comp(prev,-1,active); int sz = active.size(); int mn = 1e9, x = 1; for(auto w : active){ if(abs((sz/2)-sub[w]) < mn){ mn = abs((sz/2)-sub[w]); x = w; } } int u = k[i].second; set<ll>ne; ll kkk = get_distance(x,u); if(dist1[x]+kkk == dist1[u]){ // all nodes in subtree of x are valid prev = x; for(auto y : active){ if(above(x,y))ne.insert(y); } mn = 1e9; for(auto y : ne){ if(in[y] < mn)mn = in[y],prev = y; } }else{ // all nodes not in subtree of x are valid prev = 1; for(auto y : active){ if(!above(x,y))ne.insert(y); } mn = 1e9; for(auto y : ne){ if(in[y] < mn)mn = in[y],prev = y; } } active = ne; } int v = *active.begin(); adj[k[i].second].pb(v); adj[v].pb(k[i].second); a[p] = k[i].second; b[p] = v; w[p++] = get_distance(k[i].second,v); for(int j = 0;j<=i;++j)active.insert(k[j].second); active.insert(1); } return; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 227 ms | 672 KB | Correct: 9971 out of 500000 queries used. |
2 | Correct | 220 ms | 548 KB | Correct: 10288 out of 500000 queries used. |
3 | Correct | 229 ms | 544 KB | Correct: 10418 out of 500000 queries used. |
4 | Correct | 234 ms | 532 KB | Correct: 10493 out of 500000 queries used. |
5 | Correct | 227 ms | 516 KB | Correct: 10159 out of 500000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 227 ms | 672 KB | Correct: 9971 out of 500000 queries used. |
2 | Correct | 220 ms | 548 KB | Correct: 10288 out of 500000 queries used. |
3 | Correct | 229 ms | 544 KB | Correct: 10418 out of 500000 queries used. |
4 | Correct | 234 ms | 532 KB | Correct: 10493 out of 500000 queries used. |
5 | Correct | 227 ms | 516 KB | Correct: 10159 out of 500000 queries used. |
6 | Correct | 216 ms | 612 KB | Correct: 9935 out of 500000 queries used. |
7 | Correct | 231 ms | 744 KB | Correct: 10302 out of 500000 queries used. |
8 | Correct | 232 ms | 544 KB | Correct: 10481 out of 500000 queries used. |
9 | Correct | 234 ms | 536 KB | Correct: 10445 out of 500000 queries used. |
10 | Correct | 233 ms | 708 KB | Correct: 10131 out of 500000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 222 ms | 708 KB | Correct: 9882 out of 12000 queries used. |
2 | Correct | 217 ms | 700 KB | Correct: 9903 out of 12000 queries used. |
3 | Correct | 223 ms | 696 KB | Correct: 9981 out of 12000 queries used. |
4 | Correct | 220 ms | 596 KB | Correct: 9905 out of 12000 queries used. |
5 | Correct | 223 ms | 712 KB | Correct: 9879 out of 12000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 222 ms | 708 KB | Correct: 9882 out of 12000 queries used. |
2 | Correct | 217 ms | 700 KB | Correct: 9903 out of 12000 queries used. |
3 | Correct | 223 ms | 696 KB | Correct: 9981 out of 12000 queries used. |
4 | Correct | 220 ms | 596 KB | Correct: 9905 out of 12000 queries used. |
5 | Correct | 223 ms | 712 KB | Correct: 9879 out of 12000 queries used. |
6 | Correct | 227 ms | 596 KB | Correct: 9958 out of 12000 queries used. |
7 | Correct | 225 ms | 564 KB | Correct: 9936 out of 12000 queries used. |
8 | Correct | 220 ms | 772 KB | Correct: 9980 out of 12000 queries used. |
9 | Correct | 221 ms | 580 KB | Correct: 9946 out of 12000 queries used. |
10 | Correct | 214 ms | 648 KB | Correct: 9913 out of 12000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 227 ms | 672 KB | Correct: 9971 out of 500000 queries used. |
2 | Correct | 220 ms | 548 KB | Correct: 10288 out of 500000 queries used. |
3 | Correct | 229 ms | 544 KB | Correct: 10418 out of 500000 queries used. |
4 | Correct | 234 ms | 532 KB | Correct: 10493 out of 500000 queries used. |
5 | Correct | 227 ms | 516 KB | Correct: 10159 out of 500000 queries used. |
6 | Correct | 216 ms | 612 KB | Correct: 9935 out of 500000 queries used. |
7 | Correct | 231 ms | 744 KB | Correct: 10302 out of 500000 queries used. |
8 | Correct | 232 ms | 544 KB | Correct: 10481 out of 500000 queries used. |
9 | Correct | 234 ms | 536 KB | Correct: 10445 out of 500000 queries used. |
10 | Correct | 233 ms | 708 KB | Correct: 10131 out of 500000 queries used. |
11 | Correct | 222 ms | 708 KB | Correct: 9882 out of 12000 queries used. |
12 | Correct | 217 ms | 700 KB | Correct: 9903 out of 12000 queries used. |
13 | Correct | 223 ms | 696 KB | Correct: 9981 out of 12000 queries used. |
14 | Correct | 220 ms | 596 KB | Correct: 9905 out of 12000 queries used. |
15 | Correct | 223 ms | 712 KB | Correct: 9879 out of 12000 queries used. |
16 | Correct | 227 ms | 596 KB | Correct: 9958 out of 12000 queries used. |
17 | Correct | 225 ms | 564 KB | Correct: 9936 out of 12000 queries used. |
18 | Correct | 220 ms | 772 KB | Correct: 9980 out of 12000 queries used. |
19 | Correct | 221 ms | 580 KB | Correct: 9946 out of 12000 queries used. |
20 | Correct | 214 ms | 648 KB | Correct: 9913 out of 12000 queries used. |
21 | Correct | 230 ms | 684 KB | Correct: 9937 out of 25000 queries used. |
22 | Correct | 229 ms | 700 KB | Correct: 10320 out of 25000 queries used. |
23 | Correct | 232 ms | 580 KB | Correct: 10235 out of 25000 queries used. |
24 | Correct | 238 ms | 712 KB | Correct: 10201 out of 25000 queries used. |
25 | Correct | 226 ms | 552 KB | Correct: 10454 out of 25000 queries used. |
26 | Correct | 222 ms | 604 KB | Correct: 10356 out of 25000 queries used. |
27 | Correct | 227 ms | 544 KB | Correct: 10454 out of 25000 queries used. |
28 | Correct | 238 ms | 596 KB | Correct: 10495 out of 25000 queries used. |
29 | Correct | 229 ms | 680 KB | Correct: 10463 out of 25000 queries used. |
30 | Correct | 243 ms | 708 KB | Correct: 10414 out of 25000 queries used. |
31 | Correct | 227 ms | 540 KB | Correct: 10491 out of 25000 queries used. |
32 | Correct | 222 ms | 752 KB | Correct: 9925 out of 25000 queries used. |
33 | Correct | 230 ms | 552 KB | Correct: 10450 out of 25000 queries used. |
34 | Correct | 231 ms | 672 KB | Correct: 10484 out of 25000 queries used. |
35 | Correct | 227 ms | 596 KB | Correct: 10469 out of 25000 queries used. |
36 | Correct | 226 ms | 536 KB | Correct: 10439 out of 25000 queries used. |
37 | Correct | 228 ms | 588 KB | Correct: 10460 out of 25000 queries used. |
38 | Correct | 235 ms | 604 KB | Correct: 10471 out of 25000 queries used. |
39 | Correct | 234 ms | 540 KB | Correct: 10462 out of 25000 queries used. |
40 | Correct | 239 ms | 604 KB | Correct: 10502 out of 25000 queries used. |
41 | Correct | 240 ms | 568 KB | Correct: 10508 out of 25000 queries used. |
42 | Correct | 227 ms | 604 KB | Correct: 10457 out of 25000 queries used. |
43 | Correct | 215 ms | 656 KB | Correct: 9956 out of 25000 queries used. |
44 | Correct | 229 ms | 792 KB | Correct: 10421 out of 25000 queries used. |
45 | Correct | 222 ms | 540 KB | Correct: 10400 out of 25000 queries used. |
46 | Correct | 222 ms | 548 KB | Correct: 10366 out of 25000 queries used. |
47 | Correct | 233 ms | 824 KB | Correct: 10498 out of 25000 queries used. |
48 | Correct | 223 ms | 600 KB | Correct: 10446 out of 25000 queries used. |
49 | Correct | 227 ms | 716 KB | Correct: 10442 out of 25000 queries used. |
50 | Correct | 226 ms | 812 KB | Correct: 10492 out of 25000 queries used. |
51 | Correct | 225 ms | 696 KB | Correct: 10459 out of 25000 queries used. |
52 | Correct | 232 ms | 548 KB | Correct: 10505 out of 25000 queries used. |
53 | Correct | 234 ms | 716 KB | Correct: 10493 out of 25000 queries used. |
54 | Correct | 231 ms | 716 KB | Correct: 10370 out of 25000 queries used. |
55 | Correct | 234 ms | 592 KB | Correct: 10433 out of 25000 queries used. |
56 | Correct | 234 ms | 788 KB | Correct: 10444 out of 25000 queries used. |
57 | Correct | 231 ms | 608 KB | Correct: 10517 out of 25000 queries used. |
58 | Correct | 233 ms | 588 KB | Correct: 10429 out of 25000 queries used. |
59 | Correct | 222 ms | 540 KB | Correct: 10447 out of 25000 queries used. |
60 | Correct | 224 ms | 656 KB | Correct: 10122 out of 25000 queries used. |
61 | Correct | 226 ms | 540 KB | Correct: 10094 out of 25000 queries used. |
62 | Correct | 225 ms | 552 KB | Correct: 10079 out of 25000 queries used. |
63 | Correct | 229 ms | 588 KB | Correct: 10138 out of 25000 queries used. |
64 | Correct | 232 ms | 536 KB | Correct: 10103 out of 25000 queries used. |
65 | Correct | 224 ms | 588 KB | Correct: 10205 out of 25000 queries used. |
66 | Correct | 227 ms | 584 KB | Correct: 10116 out of 25000 queries used. |
67 | Correct | 229 ms | 844 KB | Correct: 10260 out of 25000 queries used. |
68 | Correct | 220 ms | 572 KB | Correct: 10236 out of 25000 queries used. |
69 | Correct | 221 ms | 596 KB | Correct: 10271 out of 25000 queries used. |
70 | Correct | 224 ms | 928 KB | Correct: 10261 out of 25000 queries used. |