# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
591457 | 2022-07-07T12:47:05 Z | zaneyu | City Mapping (NOI18_citymapping) | C++14 | 6 ms | 596 KB |
/*input 4 200 3 2 3 1 3 4 2 1 2 9 */ #include "citymapping.h" #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; #pragma GCC optimize("O2","unroll-loops","no-stack-protector") //order_of_key #of elements less than x // find_by_order kth element using ll=long long; using ld=long double; using pii=pair<ll,ll>; #define f first #define s second #define pb push_back #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define FILL(n,x) memset(n,x,sizeof(n)) #define ALL(_a) _a.begin(),_a.end() #define sz(x) (int)x.size() #define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end())))) const ll INF64=4e18; const int INF=0x3f3f3f3f; const ll MOD=1e9+7; const ld PI=acos(-1); const ld eps=1e-9; #define lowb(x) x&(-x) #define MNTO(x,y) x=min(x,(__typeof__(x))y) #define MXTO(x,y) x=max(x,(__typeof__(x))y) inline ll mult(ll a,ll b){ if(a<0) a+=MOD; if(b<0) b+=MOD; if(a>=MOD) a%=MOD; if(b>=MOD) b%=MOD; return (a*b)%MOD; } inline ll mypow(ll a,ll b){ if(b<=0) return 1; ll res=1LL; while(b){ if(b&1) res=mult(res,a); a=mult(a,a); b>>=1; } return res; } const int maxn=1e3+5; ll dep[maxn]; int sz[maxn]; vector<pii> v[maxn]; bool vis[maxn]; int par[maxn]; int dfs(int u,int p){ int mx=0,vv=-1; for(auto x:v[u]){ if(x.f!=p and !vis[x.f]){ if(sz[x.f]>mx){ mx=sz[x.f],vv=x.f; } } } if(vv==-1) return u; return dfs(vv,u); } void connect(int a,int b){ //cout<<a<<' '<<b<<'\n'; par[b]=a; v[a].pb({b,dep[b]-dep[a]}); sz[b]=1; sz[1]++; while(a!=1){ sz[a]++; a=par[a]; } } void find_roads(int n, int q, int A[], int B[], int W[]) { vector<pii> vv; par[1]=-1; for(int i=2;i<=n;i++){ dep[i]=get_distance(1,i); vv.pb({dep[i],i}); } sort(ALL(vv)); sz[1]=1; REP(i,sz(vv)){ REP1(j,n) vis[j]=0; int z=vv[i].s,rt=1; while(true){ int p=dfs(rt,par[rt]); if(p==rt){ connect(p,z); break; } ll a=dep[p]-dep[rt],b=dep[z]-dep[rt],c=get_distance(z,p); if(b==a+c){ connect(p,z); break; } ll tot=(a+b-c)/2; tot+=dep[rt]; while(dep[p]>tot) vis[p]=1,p=par[p]; rt=p; } } int cnt=0; REP1(i,n){ for(auto x:v[i]){ A[cnt]=i,B[cnt]=x.f,W[cnt]=x.s; ++cnt; } } }
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 552 KB | Correct: 2691 out of 500000 queries used. |
2 | Correct | 3 ms | 500 KB | Correct: 2421 out of 500000 queries used. |
3 | Correct | 2 ms | 500 KB | Correct: 4517 out of 500000 queries used. |
4 | Correct | 2 ms | 468 KB | Correct: 5567 out of 500000 queries used. |
5 | Correct | 2 ms | 500 KB | Correct: 3387 out of 500000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 552 KB | Correct: 2691 out of 500000 queries used. |
2 | Correct | 3 ms | 500 KB | Correct: 2421 out of 500000 queries used. |
3 | Correct | 2 ms | 500 KB | Correct: 4517 out of 500000 queries used. |
4 | Correct | 2 ms | 468 KB | Correct: 5567 out of 500000 queries used. |
5 | Correct | 2 ms | 500 KB | Correct: 3387 out of 500000 queries used. |
6 | Correct | 5 ms | 596 KB | Correct: 2009 out of 500000 queries used. |
7 | Correct | 4 ms | 504 KB | Correct: 2063 out of 500000 queries used. |
8 | Correct | 2 ms | 468 KB | Correct: 4244 out of 500000 queries used. |
9 | Correct | 2 ms | 468 KB | Correct: 5089 out of 500000 queries used. |
10 | Correct | 2 ms | 468 KB | Correct: 3054 out of 500000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 504 KB | Correct: 2086 out of 12000 queries used. |
2 | Correct | 4 ms | 596 KB | Correct: 2304 out of 12000 queries used. |
3 | Correct | 6 ms | 540 KB | Correct: 2457 out of 12000 queries used. |
4 | Correct | 5 ms | 556 KB | Correct: 2470 out of 12000 queries used. |
5 | Correct | 4 ms | 596 KB | Correct: 2240 out of 12000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 504 KB | Correct: 2086 out of 12000 queries used. |
2 | Correct | 4 ms | 596 KB | Correct: 2304 out of 12000 queries used. |
3 | Correct | 6 ms | 540 KB | Correct: 2457 out of 12000 queries used. |
4 | Correct | 5 ms | 556 KB | Correct: 2470 out of 12000 queries used. |
5 | Correct | 4 ms | 596 KB | Correct: 2240 out of 12000 queries used. |
6 | Correct | 5 ms | 468 KB | Correct: 2473 out of 12000 queries used. |
7 | Correct | 4 ms | 468 KB | Correct: 2382 out of 12000 queries used. |
8 | Correct | 5 ms | 596 KB | Correct: 2207 out of 12000 queries used. |
9 | Correct | 5 ms | 512 KB | Correct: 2235 out of 12000 queries used. |
10 | Correct | 4 ms | 468 KB | Correct: 2302 out of 12000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 552 KB | Correct: 2691 out of 500000 queries used. |
2 | Correct | 3 ms | 500 KB | Correct: 2421 out of 500000 queries used. |
3 | Correct | 2 ms | 500 KB | Correct: 4517 out of 500000 queries used. |
4 | Correct | 2 ms | 468 KB | Correct: 5567 out of 500000 queries used. |
5 | Correct | 2 ms | 500 KB | Correct: 3387 out of 500000 queries used. |
6 | Correct | 5 ms | 596 KB | Correct: 2009 out of 500000 queries used. |
7 | Correct | 4 ms | 504 KB | Correct: 2063 out of 500000 queries used. |
8 | Correct | 2 ms | 468 KB | Correct: 4244 out of 500000 queries used. |
9 | Correct | 2 ms | 468 KB | Correct: 5089 out of 500000 queries used. |
10 | Correct | 2 ms | 468 KB | Correct: 3054 out of 500000 queries used. |
11 | Correct | 4 ms | 504 KB | Correct: 2086 out of 12000 queries used. |
12 | Correct | 4 ms | 596 KB | Correct: 2304 out of 12000 queries used. |
13 | Correct | 6 ms | 540 KB | Correct: 2457 out of 12000 queries used. |
14 | Correct | 5 ms | 556 KB | Correct: 2470 out of 12000 queries used. |
15 | Correct | 4 ms | 596 KB | Correct: 2240 out of 12000 queries used. |
16 | Correct | 5 ms | 468 KB | Correct: 2473 out of 12000 queries used. |
17 | Correct | 4 ms | 468 KB | Correct: 2382 out of 12000 queries used. |
18 | Correct | 5 ms | 596 KB | Correct: 2207 out of 12000 queries used. |
19 | Correct | 5 ms | 512 KB | Correct: 2235 out of 12000 queries used. |
20 | Correct | 4 ms | 468 KB | Correct: 2302 out of 12000 queries used. |
21 | Correct | 5 ms | 468 KB | Correct: 2502 out of 25000 queries used. |
22 | Correct | 4 ms | 556 KB | Correct: 2071 out of 25000 queries used. |
23 | Correct | 4 ms | 504 KB | Correct: 2284 out of 25000 queries used. |
24 | Correct | 5 ms | 504 KB | Correct: 2036 out of 25000 queries used. |
25 | Correct | 2 ms | 544 KB | Correct: 4436 out of 25000 queries used. |
26 | Correct | 2 ms | 556 KB | Correct: 4358 out of 25000 queries used. |
27 | Correct | 2 ms | 468 KB | Correct: 4307 out of 25000 queries used. |
28 | Correct | 2 ms | 468 KB | Correct: 4417 out of 25000 queries used. |
29 | Correct | 2 ms | 468 KB | Correct: 4502 out of 25000 queries used. |
30 | Correct | 2 ms | 468 KB | Correct: 4442 out of 25000 queries used. |
31 | Correct | 2 ms | 468 KB | Correct: 5151 out of 25000 queries used. |
32 | Correct | 4 ms | 552 KB | Correct: 2223 out of 25000 queries used. |
33 | Correct | 2 ms | 468 KB | Correct: 5083 out of 25000 queries used. |
34 | Correct | 2 ms | 468 KB | Correct: 5158 out of 25000 queries used. |
35 | Correct | 2 ms | 468 KB | Correct: 5100 out of 25000 queries used. |
36 | Correct | 2 ms | 468 KB | Correct: 5118 out of 25000 queries used. |
37 | Correct | 2 ms | 468 KB | Correct: 5144 out of 25000 queries used. |
38 | Correct | 2 ms | 496 KB | Correct: 5102 out of 25000 queries used. |
39 | Correct | 2 ms | 552 KB | Correct: 5135 out of 25000 queries used. |
40 | Correct | 2 ms | 468 KB | Correct: 5168 out of 25000 queries used. |
41 | Correct | 2 ms | 468 KB | Correct: 5124 out of 25000 queries used. |
42 | Correct | 2 ms | 468 KB | Correct: 5203 out of 25000 queries used. |
43 | Correct | 4 ms | 596 KB | Correct: 2087 out of 25000 queries used. |
44 | Correct | 2 ms | 468 KB | Correct: 5116 out of 25000 queries used. |
45 | Correct | 2 ms | 508 KB | Correct: 5090 out of 25000 queries used. |
46 | Correct | 2 ms | 500 KB | Correct: 5068 out of 25000 queries used. |
47 | Correct | 2 ms | 468 KB | Correct: 5179 out of 25000 queries used. |
48 | Correct | 2 ms | 468 KB | Correct: 5135 out of 25000 queries used. |
49 | Correct | 2 ms | 468 KB | Correct: 5091 out of 25000 queries used. |
50 | Correct | 2 ms | 468 KB | Correct: 5105 out of 25000 queries used. |
51 | Correct | 2 ms | 504 KB | Correct: 5099 out of 25000 queries used. |
52 | Correct | 2 ms | 468 KB | Correct: 5128 out of 25000 queries used. |
53 | Correct | 2 ms | 548 KB | Correct: 5144 out of 25000 queries used. |
54 | Correct | 4 ms | 468 KB | Correct: 2333 out of 25000 queries used. |
55 | Correct | 2 ms | 548 KB | Correct: 5196 out of 25000 queries used. |
56 | Correct | 2 ms | 468 KB | Correct: 5141 out of 25000 queries used. |
57 | Correct | 2 ms | 468 KB | Correct: 5125 out of 25000 queries used. |
58 | Correct | 2 ms | 468 KB | Correct: 5115 out of 25000 queries used. |
59 | Correct | 2 ms | 500 KB | Correct: 5104 out of 25000 queries used. |
60 | Correct | 2 ms | 468 KB | Correct: 3041 out of 25000 queries used. |
61 | Correct | 2 ms | 468 KB | Correct: 3317 out of 25000 queries used. |
62 | Correct | 2 ms | 468 KB | Correct: 2917 out of 25000 queries used. |
63 | Correct | 3 ms | 468 KB | Correct: 3317 out of 25000 queries used. |
64 | Correct | 2 ms | 468 KB | Correct: 3103 out of 25000 queries used. |
65 | Correct | 5 ms | 468 KB | Correct: 2067 out of 25000 queries used. |
66 | Correct | 2 ms | 468 KB | Correct: 3228 out of 25000 queries used. |
67 | Correct | 5 ms | 468 KB | Correct: 2018 out of 25000 queries used. |
68 | Correct | 4 ms | 468 KB | Correct: 2394 out of 25000 queries used. |
69 | Correct | 4 ms | 508 KB | Correct: 2451 out of 25000 queries used. |
70 | Correct | 4 ms | 468 KB | Correct: 2414 out of 25000 queries used. |