Submission #576204

# Submission time Handle Problem Language Result Execution time Memory
576204 2022-06-12T13:49:08 Z jamezzz Reconstruction Project (JOI22_reconstruction) C++17
100 / 100
1321 ms 27192 KB
#include <bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;

#define maxn 505
#define maxm 100005

int n,m,par[maxn],rnk[maxn],s[maxm];
vector<iii> EL,c;
bool done[maxm];

void init(){
	for(int i=1;i<=n;++i)par[i]=i,rnk[i]=1;
}

int fp(int i){
	return (par[i]==i)?i:par[i]=fp(par[i]);
}

void join(int x,int y){
	x=fp(x),y=fp(y);
	if(x==y)return;
	if(rnk[x]<rnk[y])par[x]=y;
	else par[y]=x;
	if(rnk[x]==rnk[y])++rnk[x];
}

int main(){
	sf("%d%d",&n,&m);
	
	pair<ll,ll> val;
	for(int i=0;i<m;++i){
		int a,b,w;
		sf("%d%d%d",&a,&b,&w);
		EL.pb({w,{a,b}});
		
		c.pb({w,{2,-2*w}});
	}
	sort(all(EL));
	
	for(int i=0;i<m;++i){
		if(done[i])continue;
		val.fi-=1;
		val.se+=EL[i].fi;
		int cur=i;
		while(true){
			int a,b;
			tie(a,b)=EL[cur].se;
			
			init();
			int e=cur++;
			while(cur<m){
				int x,y;
				tie(x,y)=EL[cur].se;
				join(x,y);
				if(fp(a)==fp(b))break;
				++cur;
			}
			
			done[e]=true;
			if(fp(a)!=fp(b))break;
			
			int w1=EL[e].fi,w2=EL[cur].fi;
			c.pb({(w1+w2+1)/2,{-2,w1+w2}});
		}
	}
	sort(all(c));
	
	int q;sf("%d",&q);
	int cur=0;
	for(int i=0;i<q;++i){
		int x;sf("%d",&x);
		while(cur!=sz(c)&&c[cur].fi<=x){
			val.fi+=c[cur].se.fi;
			val.se+=c[cur].se.se;
			++cur;
		}
		pf("%lld\n",val.fi*x+val.se);
	}
}

Compilation message

reconstruction.cpp: In function 'int main()':
reconstruction.cpp:39:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  sf("%d%d",&n,&m);
      |    ^
reconstruction.cpp:44:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   sf("%d%d%d",&a,&b,&w);
      |     ^
reconstruction.cpp:79:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |  int q;sf("%d",&q);
      |          ^
reconstruction.cpp:82:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |   int x;sf("%d",&x);
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1068 ms 6360 KB Output is correct
21 Correct 792 ms 6484 KB Output is correct
22 Correct 834 ms 6556 KB Output is correct
23 Correct 886 ms 6412 KB Output is correct
24 Correct 1043 ms 6384 KB Output is correct
25 Correct 992 ms 6444 KB Output is correct
26 Correct 1083 ms 6548 KB Output is correct
27 Correct 1032 ms 6424 KB Output is correct
28 Correct 1020 ms 6452 KB Output is correct
29 Correct 634 ms 6496 KB Output is correct
30 Correct 1004 ms 6448 KB Output is correct
31 Correct 1047 ms 6404 KB Output is correct
32 Correct 1000 ms 6408 KB Output is correct
33 Correct 1036 ms 6560 KB Output is correct
34 Correct 499 ms 6488 KB Output is correct
35 Correct 1036 ms 6412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1113 ms 15636 KB Output is correct
5 Correct 1096 ms 15588 KB Output is correct
6 Correct 1123 ms 15576 KB Output is correct
7 Correct 665 ms 17464 KB Output is correct
8 Correct 555 ms 17552 KB Output is correct
9 Correct 486 ms 17744 KB Output is correct
10 Correct 1127 ms 15500 KB Output is correct
11 Correct 516 ms 17608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 273 ms 22184 KB Output is correct
21 Correct 274 ms 22220 KB Output is correct
22 Correct 297 ms 22244 KB Output is correct
23 Correct 280 ms 22220 KB Output is correct
24 Correct 295 ms 22180 KB Output is correct
25 Correct 250 ms 22268 KB Output is correct
26 Correct 281 ms 22256 KB Output is correct
27 Correct 297 ms 22308 KB Output is correct
28 Correct 268 ms 22236 KB Output is correct
29 Correct 274 ms 22260 KB Output is correct
30 Correct 258 ms 22216 KB Output is correct
31 Correct 263 ms 22008 KB Output is correct
32 Correct 270 ms 22688 KB Output is correct
33 Correct 277 ms 22200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1068 ms 6360 KB Output is correct
21 Correct 792 ms 6484 KB Output is correct
22 Correct 834 ms 6556 KB Output is correct
23 Correct 886 ms 6412 KB Output is correct
24 Correct 1043 ms 6384 KB Output is correct
25 Correct 992 ms 6444 KB Output is correct
26 Correct 1083 ms 6548 KB Output is correct
27 Correct 1032 ms 6424 KB Output is correct
28 Correct 1020 ms 6452 KB Output is correct
29 Correct 634 ms 6496 KB Output is correct
30 Correct 1004 ms 6448 KB Output is correct
31 Correct 1047 ms 6404 KB Output is correct
32 Correct 1000 ms 6408 KB Output is correct
33 Correct 1036 ms 6560 KB Output is correct
34 Correct 499 ms 6488 KB Output is correct
35 Correct 1036 ms 6412 KB Output is correct
36 Correct 995 ms 6656 KB Output is correct
37 Correct 783 ms 6576 KB Output is correct
38 Correct 810 ms 6700 KB Output is correct
39 Correct 886 ms 6652 KB Output is correct
40 Correct 991 ms 6676 KB Output is correct
41 Correct 1000 ms 6696 KB Output is correct
42 Correct 1020 ms 6796 KB Output is correct
43 Correct 1040 ms 6696 KB Output is correct
44 Correct 1028 ms 6676 KB Output is correct
45 Correct 619 ms 6764 KB Output is correct
46 Correct 992 ms 6656 KB Output is correct
47 Correct 1051 ms 6720 KB Output is correct
48 Correct 1014 ms 6644 KB Output is correct
49 Correct 994 ms 6756 KB Output is correct
50 Correct 492 ms 6708 KB Output is correct
51 Correct 1072 ms 6628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1068 ms 6360 KB Output is correct
21 Correct 792 ms 6484 KB Output is correct
22 Correct 834 ms 6556 KB Output is correct
23 Correct 886 ms 6412 KB Output is correct
24 Correct 1043 ms 6384 KB Output is correct
25 Correct 992 ms 6444 KB Output is correct
26 Correct 1083 ms 6548 KB Output is correct
27 Correct 1032 ms 6424 KB Output is correct
28 Correct 1020 ms 6452 KB Output is correct
29 Correct 634 ms 6496 KB Output is correct
30 Correct 1004 ms 6448 KB Output is correct
31 Correct 1047 ms 6404 KB Output is correct
32 Correct 1000 ms 6408 KB Output is correct
33 Correct 1036 ms 6560 KB Output is correct
34 Correct 499 ms 6488 KB Output is correct
35 Correct 1036 ms 6412 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 312 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1113 ms 15636 KB Output is correct
40 Correct 1096 ms 15588 KB Output is correct
41 Correct 1123 ms 15576 KB Output is correct
42 Correct 665 ms 17464 KB Output is correct
43 Correct 555 ms 17552 KB Output is correct
44 Correct 486 ms 17744 KB Output is correct
45 Correct 1127 ms 15500 KB Output is correct
46 Correct 516 ms 17608 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 273 ms 22184 KB Output is correct
49 Correct 274 ms 22220 KB Output is correct
50 Correct 297 ms 22244 KB Output is correct
51 Correct 280 ms 22220 KB Output is correct
52 Correct 295 ms 22180 KB Output is correct
53 Correct 250 ms 22268 KB Output is correct
54 Correct 281 ms 22256 KB Output is correct
55 Correct 297 ms 22308 KB Output is correct
56 Correct 268 ms 22236 KB Output is correct
57 Correct 274 ms 22260 KB Output is correct
58 Correct 258 ms 22216 KB Output is correct
59 Correct 263 ms 22008 KB Output is correct
60 Correct 270 ms 22688 KB Output is correct
61 Correct 277 ms 22200 KB Output is correct
62 Correct 995 ms 6656 KB Output is correct
63 Correct 783 ms 6576 KB Output is correct
64 Correct 810 ms 6700 KB Output is correct
65 Correct 886 ms 6652 KB Output is correct
66 Correct 991 ms 6676 KB Output is correct
67 Correct 1000 ms 6696 KB Output is correct
68 Correct 1020 ms 6796 KB Output is correct
69 Correct 1040 ms 6696 KB Output is correct
70 Correct 1028 ms 6676 KB Output is correct
71 Correct 619 ms 6764 KB Output is correct
72 Correct 992 ms 6656 KB Output is correct
73 Correct 1051 ms 6720 KB Output is correct
74 Correct 1014 ms 6644 KB Output is correct
75 Correct 994 ms 6756 KB Output is correct
76 Correct 492 ms 6708 KB Output is correct
77 Correct 1072 ms 6628 KB Output is correct
78 Correct 1256 ms 25428 KB Output is correct
79 Correct 1049 ms 27192 KB Output is correct
80 Correct 1052 ms 26440 KB Output is correct
81 Correct 1169 ms 26568 KB Output is correct
82 Correct 1276 ms 25692 KB Output is correct
83 Correct 1222 ms 25444 KB Output is correct
84 Correct 1247 ms 22836 KB Output is correct
85 Correct 1235 ms 25432 KB Output is correct
86 Correct 1321 ms 14396 KB Output is correct
87 Correct 914 ms 20360 KB Output is correct
88 Correct 1302 ms 25472 KB Output is correct
89 Correct 1227 ms 25588 KB Output is correct
90 Correct 1233 ms 25648 KB Output is correct
91 Correct 1217 ms 18188 KB Output is correct
92 Correct 766 ms 17576 KB Output is correct
93 Correct 1317 ms 26508 KB Output is correct