Submission #351015

# Submission time Handle Problem Language Result Execution time Memory
351015 2021-01-19T11:15:50 Z Kerim Swapping Cities (APIO20_swap) C++17
44 / 100
2000 ms 53728 KB
#include "swap.h"
#include "bits/stdc++.h"
#define MAXN 300009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
vector<int>u,v,w,ind;
int m,n;
int ata[MAXN],bad[MAXN],deg[MAXN];
int tap(int x){
	if(ata[x]==x)return x;
	return ata[x]=tap(ata[x]);	
}
bool cmp(int x,int y){
	return (w[x]<w[y]);	
}
const int LOG=19;
int lvl[MAXN],P[MAXN][LOG];
vector<int>adj[MAXN];
PII arr[MAXN];
void add(int x,int y){
	P[y][0]=x;adj[x].pb(y);
	//cerr<<x<<"->"<<y<<endl;	
}
void merge(int x,int y,int val){
	deg[x]++;deg[y]++;
	int so=(max(deg[x],deg[y])>=3);
	//printf("HI %d %d %d\n",x,y,val);
	x=tap(x);y=tap(y);
	if(x==y)
		bad[n]=1,ata[x]=n,add(n,x);
	else{
		add(n,x);add(n,y);
		ata[y]=ata[x]=n;
		bad[n]=bad[x]|bad[y]|so;
	}
	//printf("%d %d\n",val,bad[n]);
	arr[n++]=mp(val,bad[n]);
}
void dfs(int nd){tr(it,adj[nd])lvl[*it]=lvl[nd]+1,dfs(*it);}
void init(int N, int M,vector<int>U,vector<int> V,vector<int> W) {
	u=U;v=V;w=W;m=M;n=N;
	for(int i=0;i<m;i++)ind.pb(i);
	sort(all(ind),cmp);
	for(int i=0;i<m+n;i++)ata[i]=i;
	for(int i=0;i<m;i++)
		merge(u[ind[i]],v[ind[i]],w[ind[i]]);
	for(int j=1;j<LOG;j++)
		for(int i=0;i<n;i++)
			if(P[i][j-1])
				P[i][j]=P[P[i][j-1]][j-1];
	dfs(n-1);
}
int getMinimumFuelCapacity(int x, int y){
	if(lvl[x]<lvl[y])swap(x,y);
	for(int j=LOG-1;j>=0;j--)
		if(P[x][j] and lvl[P[x][j]]>=lvl[y])
			x=P[x][j];
	for(int j=LOG-1;j>=0;j--)
		if(P[x][j] and P[x][j]!=P[y][j])
			x=P[x][j],y=P[y][j];
	x=P[x][0];
	while(x and !arr[x].ss)x=P[x][0];
	if(!x)return -1;
	return arr[x].ff;
}

Compilation message

swap.cpp: In function 'void merge(int, int, int)':
swap.cpp:52:7: warning: operation on 'n' may be undefined [-Wsequence-point]
   52 |  arr[n++]=mp(val,bad[n]);
      |      ~^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 6 ms 7532 KB Output is correct
5 Correct 6 ms 7660 KB Output is correct
6 Correct 6 ms 7660 KB Output is correct
7 Correct 6 ms 7660 KB Output is correct
8 Correct 6 ms 7660 KB Output is correct
9 Correct 121 ms 27108 KB Output is correct
10 Correct 151 ms 31460 KB Output is correct
11 Correct 175 ms 31076 KB Output is correct
12 Correct 168 ms 32536 KB Output is correct
13 Correct 147 ms 34788 KB Output is correct
14 Correct 127 ms 27108 KB Output is correct
15 Correct 318 ms 33684 KB Output is correct
16 Correct 317 ms 32956 KB Output is correct
17 Correct 364 ms 34380 KB Output is correct
18 Execution timed out 2087 ms 36452 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 443 ms 38664 KB Output is correct
4 Correct 447 ms 43852 KB Output is correct
5 Correct 432 ms 43344 KB Output is correct
6 Correct 406 ms 43724 KB Output is correct
7 Correct 436 ms 43780 KB Output is correct
8 Correct 470 ms 42260 KB Output is correct
9 Correct 463 ms 43196 KB Output is correct
10 Correct 433 ms 42144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 6 ms 7532 KB Output is correct
6 Correct 6 ms 7660 KB Output is correct
7 Correct 6 ms 7660 KB Output is correct
8 Correct 6 ms 7660 KB Output is correct
9 Correct 6 ms 7660 KB Output is correct
10 Correct 6 ms 7660 KB Output is correct
11 Correct 6 ms 7660 KB Output is correct
12 Correct 6 ms 7660 KB Output is correct
13 Correct 6 ms 7660 KB Output is correct
14 Correct 6 ms 7660 KB Output is correct
15 Correct 6 ms 7660 KB Output is correct
16 Correct 6 ms 7660 KB Output is correct
17 Correct 5 ms 7660 KB Output is correct
18 Correct 5 ms 7660 KB Output is correct
19 Correct 7 ms 7660 KB Output is correct
20 Correct 6 ms 7660 KB Output is correct
21 Correct 6 ms 7660 KB Output is correct
22 Correct 8 ms 7788 KB Output is correct
23 Correct 7 ms 7660 KB Output is correct
24 Correct 6 ms 7788 KB Output is correct
25 Correct 10 ms 7788 KB Output is correct
26 Correct 8 ms 7916 KB Output is correct
27 Correct 6 ms 7660 KB Output is correct
28 Correct 7 ms 7916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 6 ms 7532 KB Output is correct
6 Correct 6 ms 7660 KB Output is correct
7 Correct 6 ms 7660 KB Output is correct
8 Correct 6 ms 7660 KB Output is correct
9 Correct 6 ms 7660 KB Output is correct
10 Correct 121 ms 27108 KB Output is correct
11 Correct 151 ms 31460 KB Output is correct
12 Correct 175 ms 31076 KB Output is correct
13 Correct 168 ms 32536 KB Output is correct
14 Correct 147 ms 34788 KB Output is correct
15 Correct 6 ms 7660 KB Output is correct
16 Correct 6 ms 7660 KB Output is correct
17 Correct 6 ms 7660 KB Output is correct
18 Correct 6 ms 7660 KB Output is correct
19 Correct 6 ms 7660 KB Output is correct
20 Correct 6 ms 7660 KB Output is correct
21 Correct 6 ms 7660 KB Output is correct
22 Correct 5 ms 7660 KB Output is correct
23 Correct 5 ms 7660 KB Output is correct
24 Correct 18 ms 10860 KB Output is correct
25 Correct 172 ms 32484 KB Output is correct
26 Correct 185 ms 32500 KB Output is correct
27 Correct 218 ms 32532 KB Output is correct
28 Correct 172 ms 32100 KB Output is correct
29 Correct 190 ms 31972 KB Output is correct
30 Correct 148 ms 29924 KB Output is correct
31 Correct 167 ms 32484 KB Output is correct
32 Correct 160 ms 32520 KB Output is correct
33 Correct 149 ms 35588 KB Output is correct
34 Correct 173 ms 32600 KB Output is correct
35 Correct 7 ms 7660 KB Output is correct
36 Correct 6 ms 7660 KB Output is correct
37 Correct 6 ms 7660 KB Output is correct
38 Correct 8 ms 7788 KB Output is correct
39 Correct 7 ms 7660 KB Output is correct
40 Correct 6 ms 7788 KB Output is correct
41 Correct 10 ms 7788 KB Output is correct
42 Correct 8 ms 7916 KB Output is correct
43 Correct 6 ms 7660 KB Output is correct
44 Correct 7 ms 7916 KB Output is correct
45 Correct 246 ms 42720 KB Output is correct
46 Correct 160 ms 32512 KB Output is correct
47 Correct 165 ms 32480 KB Output is correct
48 Correct 231 ms 35900 KB Output is correct
49 Correct 176 ms 40800 KB Output is correct
50 Correct 131 ms 33252 KB Output is correct
51 Correct 238 ms 38004 KB Output is correct
52 Correct 253 ms 45416 KB Output is correct
53 Correct 288 ms 48368 KB Output is correct
54 Correct 301 ms 53728 KB Output is correct
55 Correct 149 ms 35300 KB Output is correct
56 Correct 310 ms 49000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 6 ms 7532 KB Output is correct
5 Correct 6 ms 7660 KB Output is correct
6 Correct 6 ms 7660 KB Output is correct
7 Correct 6 ms 7660 KB Output is correct
8 Correct 6 ms 7660 KB Output is correct
9 Correct 121 ms 27108 KB Output is correct
10 Correct 151 ms 31460 KB Output is correct
11 Correct 175 ms 31076 KB Output is correct
12 Correct 168 ms 32536 KB Output is correct
13 Correct 147 ms 34788 KB Output is correct
14 Correct 127 ms 27108 KB Output is correct
15 Correct 318 ms 33684 KB Output is correct
16 Correct 317 ms 32956 KB Output is correct
17 Correct 364 ms 34380 KB Output is correct
18 Execution timed out 2087 ms 36452 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 6 ms 7532 KB Output is correct
6 Correct 6 ms 7660 KB Output is correct
7 Correct 6 ms 7660 KB Output is correct
8 Correct 6 ms 7660 KB Output is correct
9 Correct 6 ms 7660 KB Output is correct
10 Correct 121 ms 27108 KB Output is correct
11 Correct 151 ms 31460 KB Output is correct
12 Correct 175 ms 31076 KB Output is correct
13 Correct 168 ms 32536 KB Output is correct
14 Correct 147 ms 34788 KB Output is correct
15 Correct 127 ms 27108 KB Output is correct
16 Correct 318 ms 33684 KB Output is correct
17 Correct 317 ms 32956 KB Output is correct
18 Correct 364 ms 34380 KB Output is correct
19 Execution timed out 2087 ms 36452 KB Time limit exceeded