# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
527507 |
2022-02-17T13:54:42 Z |
zaneyu |
Parkovi (COCI22_parkovi) |
C++14 |
|
1287 ms |
54152 KB |
/*input
2 1
1 2 3
*/
#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;
//#pragma GCC optimize("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>;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#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()))))
#define MP make_pair
const ll INF64=4e17;
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)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
out<<P.f<<' '<<P.s;
return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
REP(i,sz(V)) out<<V[i]+1<<((i!=sz(V)-1)?" ":"");
return out;
}
ll mult(ll a,ll b){
return ((a%MOD)*(b%MOD))%MOD;
}
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=1e6+5;
vector<pii> v[maxn];
ll k;
vector<int> anss;
pii dfs(int u,int p,ll pv){
ll mx=0,mx2=-INF64;
for(auto x:v[u]){
if(x.f!=p){
pii z=dfs(x.f,u,x.s);
if(!z.f){
MXTO(mx,z.s);
}
else{
MXTO(mx2,z.s);
}
}
}
pii ans;
if(mx2>=mx){
ans.f=1;
ans.s=(mx2-pv);
}
else{
ans.f=0;
ans.s=(mx+pv);
}
if(!ans.f and ans.s>k){
anss.pb(u);
ans.f=1;
ans.s=k-pv;
}
if(ans.f and ans.s<0) ans.f=0,ans.s=0;
return ans;
}
bool in[maxn];
int main(){
int n,z;
cin>>n>>z;
REP(i,n-1){
int a,b,c;
cin>>a>>b>>c;
--a;
--b;
v[a].pb({b,c});
v[b].pb({a,c});
}
ll l=0,r=INF64;
while(l<r){
ll mid=(l+r)/2;
k=mid;
dfs(0,-1,INF64);
if(sz(anss)<=z) r=mid;
else l=mid+1;
anss.clear();
}
k=l;
dfs(0,-1,INF64);
cout<<l<<'\n';
for(int x:anss) in[x]=1;
int p=0;
while(sz(anss)<z){
while(in[p]) ++p;
anss.pb(p);
++p;
}
cout<<anss;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
Output is correct |
2 |
Correct |
13 ms |
23756 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
15 ms |
23780 KB |
Output is correct |
5 |
Correct |
12 ms |
23756 KB |
Output is correct |
6 |
Correct |
16 ms |
23756 KB |
Output is correct |
7 |
Correct |
14 ms |
23724 KB |
Output is correct |
8 |
Correct |
13 ms |
23756 KB |
Output is correct |
9 |
Correct |
14 ms |
23788 KB |
Output is correct |
10 |
Correct |
15 ms |
23676 KB |
Output is correct |
11 |
Correct |
16 ms |
23756 KB |
Output is correct |
12 |
Correct |
15 ms |
23788 KB |
Output is correct |
13 |
Correct |
12 ms |
23720 KB |
Output is correct |
14 |
Correct |
12 ms |
23784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
403 ms |
49856 KB |
Output is correct |
2 |
Correct |
521 ms |
50144 KB |
Output is correct |
3 |
Correct |
406 ms |
37896 KB |
Output is correct |
4 |
Correct |
1257 ms |
37256 KB |
Output is correct |
5 |
Correct |
1144 ms |
36740 KB |
Output is correct |
6 |
Correct |
1223 ms |
36956 KB |
Output is correct |
7 |
Correct |
1142 ms |
35716 KB |
Output is correct |
8 |
Correct |
1145 ms |
34856 KB |
Output is correct |
9 |
Correct |
1287 ms |
33512 KB |
Output is correct |
10 |
Correct |
1201 ms |
37060 KB |
Output is correct |
11 |
Correct |
912 ms |
37996 KB |
Output is correct |
12 |
Correct |
795 ms |
38256 KB |
Output is correct |
13 |
Correct |
914 ms |
39764 KB |
Output is correct |
14 |
Correct |
768 ms |
37180 KB |
Output is correct |
15 |
Correct |
786 ms |
36752 KB |
Output is correct |
16 |
Correct |
813 ms |
38120 KB |
Output is correct |
17 |
Correct |
826 ms |
37492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
456 ms |
51996 KB |
Output is correct |
2 |
Correct |
455 ms |
51600 KB |
Output is correct |
3 |
Correct |
428 ms |
49972 KB |
Output is correct |
4 |
Correct |
421 ms |
50008 KB |
Output is correct |
5 |
Correct |
481 ms |
53984 KB |
Output is correct |
6 |
Correct |
503 ms |
53072 KB |
Output is correct |
7 |
Correct |
500 ms |
54152 KB |
Output is correct |
8 |
Correct |
455 ms |
52036 KB |
Output is correct |
9 |
Correct |
445 ms |
51780 KB |
Output is correct |
10 |
Correct |
413 ms |
49092 KB |
Output is correct |
11 |
Correct |
426 ms |
46900 KB |
Output is correct |
12 |
Correct |
490 ms |
51292 KB |
Output is correct |
13 |
Correct |
499 ms |
50764 KB |
Output is correct |
14 |
Correct |
463 ms |
49724 KB |
Output is correct |
15 |
Correct |
389 ms |
47812 KB |
Output is correct |
16 |
Correct |
376 ms |
46792 KB |
Output is correct |
17 |
Correct |
395 ms |
46788 KB |
Output is correct |
18 |
Correct |
397 ms |
47816 KB |
Output is correct |
19 |
Correct |
425 ms |
49376 KB |
Output is correct |
20 |
Correct |
438 ms |
49732 KB |
Output is correct |
21 |
Correct |
421 ms |
48820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
Output is correct |
2 |
Correct |
13 ms |
23756 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
15 ms |
23780 KB |
Output is correct |
5 |
Correct |
12 ms |
23756 KB |
Output is correct |
6 |
Correct |
16 ms |
23756 KB |
Output is correct |
7 |
Correct |
14 ms |
23724 KB |
Output is correct |
8 |
Correct |
13 ms |
23756 KB |
Output is correct |
9 |
Correct |
14 ms |
23788 KB |
Output is correct |
10 |
Correct |
15 ms |
23676 KB |
Output is correct |
11 |
Correct |
16 ms |
23756 KB |
Output is correct |
12 |
Correct |
15 ms |
23788 KB |
Output is correct |
13 |
Correct |
12 ms |
23720 KB |
Output is correct |
14 |
Correct |
12 ms |
23784 KB |
Output is correct |
15 |
Correct |
403 ms |
49856 KB |
Output is correct |
16 |
Correct |
521 ms |
50144 KB |
Output is correct |
17 |
Correct |
406 ms |
37896 KB |
Output is correct |
18 |
Correct |
1257 ms |
37256 KB |
Output is correct |
19 |
Correct |
1144 ms |
36740 KB |
Output is correct |
20 |
Correct |
1223 ms |
36956 KB |
Output is correct |
21 |
Correct |
1142 ms |
35716 KB |
Output is correct |
22 |
Correct |
1145 ms |
34856 KB |
Output is correct |
23 |
Correct |
1287 ms |
33512 KB |
Output is correct |
24 |
Correct |
1201 ms |
37060 KB |
Output is correct |
25 |
Correct |
912 ms |
37996 KB |
Output is correct |
26 |
Correct |
795 ms |
38256 KB |
Output is correct |
27 |
Correct |
914 ms |
39764 KB |
Output is correct |
28 |
Correct |
768 ms |
37180 KB |
Output is correct |
29 |
Correct |
786 ms |
36752 KB |
Output is correct |
30 |
Correct |
813 ms |
38120 KB |
Output is correct |
31 |
Correct |
826 ms |
37492 KB |
Output is correct |
32 |
Correct |
456 ms |
51996 KB |
Output is correct |
33 |
Correct |
455 ms |
51600 KB |
Output is correct |
34 |
Correct |
428 ms |
49972 KB |
Output is correct |
35 |
Correct |
421 ms |
50008 KB |
Output is correct |
36 |
Correct |
481 ms |
53984 KB |
Output is correct |
37 |
Correct |
503 ms |
53072 KB |
Output is correct |
38 |
Correct |
500 ms |
54152 KB |
Output is correct |
39 |
Correct |
455 ms |
52036 KB |
Output is correct |
40 |
Correct |
445 ms |
51780 KB |
Output is correct |
41 |
Correct |
413 ms |
49092 KB |
Output is correct |
42 |
Correct |
426 ms |
46900 KB |
Output is correct |
43 |
Correct |
490 ms |
51292 KB |
Output is correct |
44 |
Correct |
499 ms |
50764 KB |
Output is correct |
45 |
Correct |
463 ms |
49724 KB |
Output is correct |
46 |
Correct |
389 ms |
47812 KB |
Output is correct |
47 |
Correct |
376 ms |
46792 KB |
Output is correct |
48 |
Correct |
395 ms |
46788 KB |
Output is correct |
49 |
Correct |
397 ms |
47816 KB |
Output is correct |
50 |
Correct |
425 ms |
49376 KB |
Output is correct |
51 |
Correct |
438 ms |
49732 KB |
Output is correct |
52 |
Correct |
421 ms |
48820 KB |
Output is correct |
53 |
Correct |
1034 ms |
33392 KB |
Output is correct |
54 |
Correct |
1134 ms |
33604 KB |
Output is correct |
55 |
Correct |
1173 ms |
33996 KB |
Output is correct |
56 |
Correct |
1114 ms |
34236 KB |
Output is correct |
57 |
Correct |
1165 ms |
35044 KB |
Output is correct |
58 |
Correct |
1068 ms |
33436 KB |
Output is correct |
59 |
Correct |
1250 ms |
36940 KB |
Output is correct |
60 |
Correct |
1131 ms |
33976 KB |
Output is correct |
61 |
Correct |
1008 ms |
33136 KB |
Output is correct |
62 |
Correct |
1006 ms |
34784 KB |
Output is correct |
63 |
Correct |
1175 ms |
34008 KB |
Output is correct |
64 |
Correct |
1066 ms |
36412 KB |
Output is correct |
65 |
Correct |
1202 ms |
33760 KB |
Output is correct |
66 |
Correct |
1103 ms |
34852 KB |
Output is correct |
67 |
Correct |
1045 ms |
33136 KB |
Output is correct |
68 |
Correct |
1254 ms |
36916 KB |
Output is correct |
69 |
Correct |
436 ms |
47816 KB |
Output is correct |
70 |
Correct |
400 ms |
46656 KB |
Output is correct |
71 |
Correct |
480 ms |
50056 KB |
Output is correct |
72 |
Correct |
355 ms |
33060 KB |
Output is correct |
73 |
Correct |
329 ms |
33704 KB |
Output is correct |
74 |
Correct |
344 ms |
35432 KB |
Output is correct |
75 |
Correct |
805 ms |
35208 KB |
Output is correct |
76 |
Correct |
856 ms |
35596 KB |
Output is correct |
77 |
Correct |
798 ms |
34980 KB |
Output is correct |
78 |
Correct |
786 ms |
35820 KB |
Output is correct |