Submission #34554618
Source Code Expand
#include<bits/stdc++.h>
#define int long long
using namespace std;int n,m,a[200010],head[200010],to[400010],nxt[400010],s[200010],x,y,ans,tot;bool vis[200010];void add(int x,int y){to[++tot]=y,nxt[tot]=head[x],head[x]=tot,s[y]+=a[x];}set<pair<int,int> >g;void Solve_Test(){scanf("%lld%lld",&n,&m);for(int i=1;i<=n;++i)scanf("%lld",&a[i]);for(;m--;)scanf("%lld%lld",&x,&y),add(x,y),add(y,x);for(int i=1;i<=n;++i)g.insert(make_pair(s[i],i));for(int t=1;t<=n;++t){x=(*g.begin()).second,ans=max(ans,(*g.begin()).first),g.erase(g.begin()),vis[x]=1;for(int i=head[x];i;i=nxt[i])if(!vis[to[i]])g.erase(make_pair(s[to[i]],to[i])),s[to[i]]-=a[x],g.insert(make_pair(s[to[i]],to[i]));}printf("%lld",ans);}const bool BASE=0;int T=1;signed main(){if(BASE)cin>>T;while(T--)Solve_Test();return 0;}
Submission Info
| Submission Time |
|
| Task |
E - Erasing Vertices 2 |
| User |
Treap |
| Language |
C++ (GCC 9.2.1) |
| Score |
500 |
| Code Size |
784 Byte |
| Status |
AC |
| Exec Time |
308 ms |
| Memory |
27112 KiB |
Compile Error
./Main.cpp: In function ‘void Solve_Test()’:
./Main.cpp:3:233: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
3 | using namespace std;int n,m,a[200010],head[200010],to[400010],nxt[400010],s[200010],x,y,ans,tot;bool vis[200010];void add(int x,int y){to[++tot]=y,nxt[tot]=head[x],head[x]=tot,s[y]+=a[x];}set<pair<int,int> >g;void Solve_Test(){scanf("%lld%lld",&n,&m);for(int i=1;i<=n;++i)scanf("%lld",&a[i]);for(;m--;)scanf("%lld%lld",&x,&y),add(x,y),add(y,x);for(int i=1;i<=n;++i)g.insert(make_pair(s[i],i));for(int t=1;t<=n;++t){x=(*g.begin()).second,ans=max(ans,(*g.begin()).first),g.erase(g.begin()),vis[x]=1;for(int i=head[x];i;i=nxt[i])if(!vis[to[i]])g.erase(make_pair(s[to[i]],to[i])),s[to[i]]-=a[x],g.insert(make_pair(s[to[i]],to[i]));}printf("%lld",ans);}const bool BASE=0;int T=1;signed main(){if(BASE)cin>>T;while(T--)Solve_Test();return 0;}
| ~~~~~^~~~~~~~~~~~~~~~~~
./Main.cpp:3:278: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
3 | using namespace std;int n,m,a[200010],head[200010],to[400010],nxt[400010],s[200010],x,y,ans,tot;bool vis[200010];void add(int x,int y){to[++tot]=y,nxt[tot]=head[x],head[x]=tot,s[y]+=a[x];}set<pair<int,int> >g;void Solve_Test(){scanf("%lld%lld",&n,&m);for(int i=1;i<=n;++i)scanf("%lld",&a[i]);for(;m--;)scanf("%lld%lld",&x,&y),add(x,y),add(y,x);for(int i=1;i<=n;++i)g.insert(make_pair(s[i],i));for(int t=1;t<=n;++t){x=(*g.begin()).second,ans=max(ans,(*g.begin()).first),g.erase(g.begin()),vis[x]=1;for(int i=head[x];i;i=nxt[i])if(!vis[to[i]])g.erase(make_pair(s[to[i]],to[i])),s[to[i]]-=a[x],g.insert(make_pair(s[to[i]],to[i]));}printf("%lld",ans);}const bool BASE=0;int T=1;signed main(){if(...
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example_00.txt, example_01.txt |
| All |
example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt |
| Case Name |
Status |
Exec Time |
Memory |
| example_00.txt |
AC |
6 ms |
3616 KiB |
| example_01.txt |
AC |
2 ms |
3752 KiB |
| test_00.txt |
AC |
226 ms |
24248 KiB |
| test_01.txt |
AC |
96 ms |
14796 KiB |
| test_02.txt |
AC |
116 ms |
10900 KiB |
| test_03.txt |
AC |
261 ms |
25944 KiB |
| test_04.txt |
AC |
170 ms |
15132 KiB |
| test_05.txt |
AC |
87 ms |
11508 KiB |
| test_06.txt |
AC |
231 ms |
21956 KiB |
| test_07.txt |
AC |
39 ms |
7032 KiB |
| test_08.txt |
AC |
36 ms |
6028 KiB |
| test_09.txt |
AC |
77 ms |
15236 KiB |
| test_10.txt |
AC |
3 ms |
4040 KiB |
| test_11.txt |
AC |
44 ms |
10672 KiB |
| test_12.txt |
AC |
28 ms |
8160 KiB |
| test_13.txt |
AC |
10 ms |
4436 KiB |
| test_14.txt |
AC |
308 ms |
26836 KiB |
| test_15.txt |
AC |
271 ms |
26428 KiB |
| test_16.txt |
AC |
296 ms |
26696 KiB |
| test_17.txt |
AC |
285 ms |
26748 KiB |
| test_18.txt |
AC |
303 ms |
26748 KiB |
| test_19.txt |
AC |
288 ms |
26648 KiB |
| test_20.txt |
AC |
287 ms |
26920 KiB |
| test_21.txt |
AC |
297 ms |
27112 KiB |
| test_22.txt |
AC |
293 ms |
26824 KiB |
| test_23.txt |
AC |
304 ms |
26972 KiB |
| test_24.txt |
AC |
86 ms |
9996 KiB |
| test_25.txt |
AC |
84 ms |
9792 KiB |
| test_26.txt |
AC |
84 ms |
9804 KiB |
| test_27.txt |
AC |
85 ms |
9804 KiB |
| test_28.txt |
AC |
86 ms |
9832 KiB |
| test_29.txt |
AC |
88 ms |
9940 KiB |