# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1110924 |
2024-11-11T02:48:00 Z |
modwwe |
Paths (RMI21_paths) |
C++17 |
|
600 ms |
277544 KB |
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("conserve-stack")
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void phongbeo();
const int inf = 1e18;
const int mod2 = 1e9 + 7;
const int mod1 = 998244353;
const ll base=67;
int add(int x,int y)
{
assert(abs(x)<=mod2);
assert(abs(y)<=mod2);
if(x+y>=mod2) x-=mod2;
if(x+y<0) x+=mod2;
return x+y;
}
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a, b, c;
};
struct id
{
int a, b, c, d;
};
struct ie
{
int a, b, c, d, e;
};
ll n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int i, s10, s12,k1,k2,k3,s11,t,lim,w,l,r;
int kk;
int el = 19;
main()
{
if(fopen(task".inp","r"))
{
fin(task);
fou(task);
}
NHP
/// cin>>s1;
// modwwe
phongbeo();
// checktime
}
set<pair<int,int>>sold;
set<pair<int,int>> snew;
int cost[100001],d[100001],par[100001], dist[100001], d2[100001],costnew[100001],ans[100001],b[100001];
vector<ib> v[100001];
void dfs(int x,int y)
{
cost[x]=0;
d[x]=x;
int hihi=0;
par[x]=y;
/// neu canh co nhieu con thi uu tien con lon nhat duoc lay truoc
for(auto f:v[x])
if(f.a^y)
{
dfs(f.a,x);
cost[d[f.a]]+=f.b;
dist[f.a]=f.b;
if(cost[d[f.a]]>hihi)
d[x]=d[f.a],hihi=cost[d[f.a]],b[x]=f.a;
}
}
void add(ib a,int c)
{
pair<int,int> dd= {a.a,a.b};
if(sold.find(dd)!=sold.end())
{
sold.erase(dd);
dd.first+=c;
sold.insert(dd);
}
else
{
if(snew.find(dd)==snew.end())
{
assert(0);
exit(0);
}
assert(snew.find(dd)!=snew.end());
snew.erase(dd);
s4+=c;
dd.first+=c;
snew.insert(dd);
}
if(!sold.empty()&&!snew.empty()&&sold.rbegin()->first>snew.begin()->first)
{
pair<int,int> x=*sold.rbegin();
sold.erase(x);
s4+=x.first;
snew.insert(x);
pair<int,int> y=*snew.begin();
s4-=y.first;
snew.erase(y);
sold.insert(y);
}
}
void kiki(int x,int y)///x->y
{
costnew[x]=costnew[par[x]]+dist[x];
d2[x]=d2[par[x]];
if(d2[x]==0)d2[x]=x;
for(auto f:v[x])
if(par[x]!=f.a&&f.a!=y)
{
if(cost[d[f.a]]>costnew[x])
{
d2[x]=d[f.a];
costnew[x]=cost[d[f.a]];
}
}
ib ditmemay= {costnew[x],d2[x]};
add(ditmemay,dist[y]);///upd costnew+dist[y]
ditmemay= {cost[d[y]],d[y]};
add(ditmemay,-dist[y]);///erase d[y]-=dist[y]
cost[d[y]]-=dist[y];
}
void del(int x,int y)/// y->x
{
ib ditmemay{costnew[x]+dist[y],d2[x]};
add(ditmemay,-dist[y]);/// erase costnew-=dist[y]
ditmemay= {cost[d[y]],d[y]};
add(ditmemay,dist[y]);///add d[y]+=dist[y];
cost[d[y]]+=dist[y];
}
void skibidi(int x,int y)///x->y
{
costnew[x]=costnew[par[x]]+dist[x];
d2[x]=d2[par[x]];
if(d2[x]==0)d2[x]=x;
if(cost[d[x]]>costnew[x])
{
d2[x]=d[x];
costnew[x]=cost[d[x]];
}
ib ditmemay= {costnew[x],d2[x]};
add(ditmemay,dist[y]);///upd costnew+dist[y]
ditmemay= {cost[d[y]],d[y]};
add(ditmemay,-dist[y]);///erase d[y]-=dist[y]
cost[d[y]]-=dist[y];
}
vector<int> cc[100001];
void dfs2(int x,int y)
{
ans[x]=s4;
for(auto f:snew)
cc[x].pb(f.first);
if(b[x]!=0)
{
kiki(x,b[x]);
dfs2(b[x],x);
del(x,b[x]);
}
for(auto f:v[x])
if(f.a!=y&&f.a!=b[x])
{
skibidi(x,f.a);
dfs2(f.a,x);
del(x,f.a);
}
}
void phongbeo()
{
cin>>n>>k;
s9=0;
for(int i=1; i<=n; i++)
cin>>l>>r>>s2,v[l].pb({r,s2}),v[r].pb({l,s2}),s9+=s2;
if(n==k)
{
for(int i=1; i<=n; i++)
cout<<s9,down
exit(0);
}
dfs(1,0);
for(int i=1; i<=n; i++)
sold.insert({cost[i],i});
s4=0;
for(int i=1; i<=k; i++)
{
pair<int,int> x=*sold.rbegin();
snew.insert(x);
s4+=x.first;
sold.erase(prev(sold.end()));
}
dfs2(1,0);
for(int i=1; i<=n; i++)
cout<<ans[i],down
}
Compilation message
Main.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
58 | main()
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define fin(x) freopen(x".inp","r",stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:62:9: note: in expansion of macro 'fin'
62 | fin(task);
| ^~~
Main.cpp:14:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define fou(x) freopen(x".ans","w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:63:9: note: in expansion of macro 'fou'
63 | fou(task);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10832 KB |
Output is correct |
2 |
Correct |
2 ms |
10832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10832 KB |
Output is correct |
2 |
Correct |
2 ms |
10832 KB |
Output is correct |
3 |
Correct |
3 ms |
10832 KB |
Output is correct |
4 |
Correct |
3 ms |
10832 KB |
Output is correct |
5 |
Correct |
3 ms |
10832 KB |
Output is correct |
6 |
Correct |
3 ms |
10832 KB |
Output is correct |
7 |
Correct |
3 ms |
10832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10832 KB |
Output is correct |
2 |
Correct |
2 ms |
10832 KB |
Output is correct |
3 |
Correct |
3 ms |
10832 KB |
Output is correct |
4 |
Correct |
3 ms |
10832 KB |
Output is correct |
5 |
Correct |
3 ms |
10832 KB |
Output is correct |
6 |
Correct |
3 ms |
10832 KB |
Output is correct |
7 |
Correct |
3 ms |
10832 KB |
Output is correct |
8 |
Correct |
5 ms |
11856 KB |
Output is correct |
9 |
Correct |
4 ms |
11344 KB |
Output is correct |
10 |
Correct |
4 ms |
11344 KB |
Output is correct |
11 |
Correct |
5 ms |
11868 KB |
Output is correct |
12 |
Correct |
4 ms |
11856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10832 KB |
Output is correct |
2 |
Correct |
2 ms |
10832 KB |
Output is correct |
3 |
Correct |
3 ms |
10832 KB |
Output is correct |
4 |
Correct |
3 ms |
10832 KB |
Output is correct |
5 |
Correct |
3 ms |
10832 KB |
Output is correct |
6 |
Correct |
3 ms |
10832 KB |
Output is correct |
7 |
Correct |
3 ms |
10832 KB |
Output is correct |
8 |
Correct |
5 ms |
11856 KB |
Output is correct |
9 |
Correct |
4 ms |
11344 KB |
Output is correct |
10 |
Correct |
4 ms |
11344 KB |
Output is correct |
11 |
Correct |
5 ms |
11868 KB |
Output is correct |
12 |
Correct |
4 ms |
11856 KB |
Output is correct |
13 |
Correct |
24 ms |
27472 KB |
Output is correct |
14 |
Correct |
7 ms |
13136 KB |
Output is correct |
15 |
Correct |
5 ms |
11600 KB |
Output is correct |
16 |
Correct |
19 ms |
18980 KB |
Output is correct |
17 |
Correct |
15 ms |
19204 KB |
Output is correct |
18 |
Correct |
8 ms |
13904 KB |
Output is correct |
19 |
Correct |
29 ms |
27208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
248 ms |
27020 KB |
Output is correct |
2 |
Correct |
231 ms |
29000 KB |
Output is correct |
3 |
Correct |
179 ms |
26952 KB |
Output is correct |
4 |
Correct |
243 ms |
26844 KB |
Output is correct |
5 |
Correct |
262 ms |
27876 KB |
Output is correct |
6 |
Correct |
245 ms |
27072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10832 KB |
Output is correct |
2 |
Correct |
2 ms |
10832 KB |
Output is correct |
3 |
Correct |
3 ms |
10832 KB |
Output is correct |
4 |
Correct |
3 ms |
10832 KB |
Output is correct |
5 |
Correct |
3 ms |
10832 KB |
Output is correct |
6 |
Correct |
3 ms |
10832 KB |
Output is correct |
7 |
Correct |
3 ms |
10832 KB |
Output is correct |
8 |
Correct |
5 ms |
11856 KB |
Output is correct |
9 |
Correct |
4 ms |
11344 KB |
Output is correct |
10 |
Correct |
4 ms |
11344 KB |
Output is correct |
11 |
Correct |
5 ms |
11868 KB |
Output is correct |
12 |
Correct |
4 ms |
11856 KB |
Output is correct |
13 |
Correct |
24 ms |
27472 KB |
Output is correct |
14 |
Correct |
7 ms |
13136 KB |
Output is correct |
15 |
Correct |
5 ms |
11600 KB |
Output is correct |
16 |
Correct |
19 ms |
18980 KB |
Output is correct |
17 |
Correct |
15 ms |
19204 KB |
Output is correct |
18 |
Correct |
8 ms |
13904 KB |
Output is correct |
19 |
Correct |
29 ms |
27208 KB |
Output is correct |
20 |
Correct |
248 ms |
27020 KB |
Output is correct |
21 |
Correct |
231 ms |
29000 KB |
Output is correct |
22 |
Correct |
179 ms |
26952 KB |
Output is correct |
23 |
Correct |
243 ms |
26844 KB |
Output is correct |
24 |
Correct |
262 ms |
27876 KB |
Output is correct |
25 |
Correct |
245 ms |
27072 KB |
Output is correct |
26 |
Execution timed out |
1065 ms |
277544 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |