답안 #351006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
351006 2021-01-19T11:10:52 Z Kerim 자매 도시 (APIO20_swap) C++17
37 / 100
2000 ms 56288 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=18;
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]]);
	dfs(n-1);
}
int getMinimumFuelCapacity(int X, int Y){
	while(X!=Y){
		if(lvl[X]>lvl[Y])X=P[X][0];
		else Y=P[Y][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]);
      |      ~^~
# 결과 실행 시간 메모리 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 7 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 7788 KB Output is correct
9 Correct 96 ms 28132 KB Output is correct
10 Correct 121 ms 32740 KB Output is correct
11 Correct 121 ms 32356 KB Output is correct
12 Correct 128 ms 33892 KB Output is correct
13 Correct 103 ms 36344 KB Output is correct
14 Correct 119 ms 28388 KB Output is correct
15 Correct 369 ms 37232 KB Output is correct
16 Correct 385 ms 36364 KB Output is correct
17 Correct 375 ms 37860 KB Output is correct
18 Execution timed out 2064 ms 40036 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Execution timed out 2065 ms 40232 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 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 7 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 7788 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 7 ms 7660 KB Output is correct
14 Correct 6 ms 7660 KB Output is correct
15 Correct 7 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 7 ms 7660 KB Output is correct
19 Correct 8 ms 7660 KB Output is correct
20 Correct 6 ms 7660 KB Output is correct
21 Correct 8 ms 7660 KB Output is correct
22 Correct 6 ms 7788 KB Output is correct
23 Correct 6 ms 7660 KB Output is correct
24 Correct 7 ms 7788 KB Output is correct
25 Correct 7 ms 7788 KB Output is correct
26 Correct 6 ms 7916 KB Output is correct
27 Correct 6 ms 7660 KB Output is correct
28 Correct 7 ms 7916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 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 7 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 7788 KB Output is correct
10 Correct 96 ms 28132 KB Output is correct
11 Correct 121 ms 32740 KB Output is correct
12 Correct 121 ms 32356 KB Output is correct
13 Correct 128 ms 33892 KB Output is correct
14 Correct 103 ms 36344 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 7 ms 7660 KB Output is correct
19 Correct 6 ms 7660 KB Output is correct
20 Correct 7 ms 7660 KB Output is correct
21 Correct 6 ms 7660 KB Output is correct
22 Correct 6 ms 7660 KB Output is correct
23 Correct 7 ms 7660 KB Output is correct
24 Correct 20 ms 11032 KB Output is correct
25 Correct 130 ms 33508 KB Output is correct
26 Correct 125 ms 33636 KB Output is correct
27 Correct 134 ms 33508 KB Output is correct
28 Correct 140 ms 33160 KB Output is correct
29 Correct 131 ms 33008 KB Output is correct
30 Correct 121 ms 30920 KB Output is correct
31 Correct 148 ms 33952 KB Output is correct
32 Correct 156 ms 33548 KB Output is correct
33 Correct 101 ms 36580 KB Output is correct
34 Correct 159 ms 33892 KB Output is correct
35 Correct 8 ms 7660 KB Output is correct
36 Correct 6 ms 7660 KB Output is correct
37 Correct 8 ms 7660 KB Output is correct
38 Correct 6 ms 7788 KB Output is correct
39 Correct 6 ms 7660 KB Output is correct
40 Correct 7 ms 7788 KB Output is correct
41 Correct 7 ms 7788 KB Output is correct
42 Correct 6 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 204 ms 44896 KB Output is correct
46 Correct 133 ms 33508 KB Output is correct
47 Correct 136 ms 33636 KB Output is correct
48 Correct 152 ms 37096 KB Output is correct
49 Correct 147 ms 42932 KB Output is correct
50 Correct 114 ms 35120 KB Output is correct
51 Correct 165 ms 39984 KB Output is correct
52 Correct 217 ms 47840 KB Output is correct
53 Correct 250 ms 50912 KB Output is correct
54 Correct 255 ms 56288 KB Output is correct
55 Correct 114 ms 36388 KB Output is correct
56 Correct 224 ms 51552 KB Output is correct
# 결과 실행 시간 메모리 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 7 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 7788 KB Output is correct
9 Correct 96 ms 28132 KB Output is correct
10 Correct 121 ms 32740 KB Output is correct
11 Correct 121 ms 32356 KB Output is correct
12 Correct 128 ms 33892 KB Output is correct
13 Correct 103 ms 36344 KB Output is correct
14 Correct 119 ms 28388 KB Output is correct
15 Correct 369 ms 37232 KB Output is correct
16 Correct 385 ms 36364 KB Output is correct
17 Correct 375 ms 37860 KB Output is correct
18 Execution timed out 2064 ms 40036 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 7 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 7 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 7788 KB Output is correct
10 Correct 96 ms 28132 KB Output is correct
11 Correct 121 ms 32740 KB Output is correct
12 Correct 121 ms 32356 KB Output is correct
13 Correct 128 ms 33892 KB Output is correct
14 Correct 103 ms 36344 KB Output is correct
15 Correct 119 ms 28388 KB Output is correct
16 Correct 369 ms 37232 KB Output is correct
17 Correct 385 ms 36364 KB Output is correct
18 Correct 375 ms 37860 KB Output is correct
19 Execution timed out 2064 ms 40036 KB Time limit exceeded