답안 #965755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965755 2024-04-19T06:59:32 Z willychan 자매 도시 (APIO20_swap) C++17
0 / 100
135 ms 23856 KB
#include "swap.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge{
	int a;
	int b;
	int w;
};
vector<edge> es;
int n;
int m;
vector<vector<int> > side;
vector<int> gtime;
vector<pair<int,int> > p;
vector<bool> cyc;
vector<int> maxd;
vector<vector<int> > ele;
vector<int> deg;
int query(int x){
	while(p[x].first!=x) x=p[x].first;
	return x;
}

void init(int N, int M,std::vector<int> U, std::vector<int> V, std::vector<int> W) {
	n = N;
	m = M;
	side.resize(n);
	gtime.resize(n,-1);
	p.resize(n);
	cyc.resize(n);
	maxd.resize(n);
	ele.resize(n);
	deg.resize(n,0);
	for(int i=0;i<M;i++){
		es.push_back({U[i],V[i],W[i]});
	}
	sort(es.begin(),es.end(),[](const edge &x,const edge &y){return x.w<y.w;});
	for(int i=0;i<n;i++){
		ele[i].push_back(i)	;
		p[i]={i,0};
	}
	for(int i=0;i<m;i++){
		int u = es[i].a;
		int v = es[i].b;
		deg[es[i].a]++;
		deg[es[i].b]++;
		u = query(u);
		v = query(v);
		if(u==v){
			cyc[u]=1;
			maxd[u] = max({maxd[u],deg[es[i].a],deg[es[i].b]});
			if(!gtime[u]){
				for(auto e : ele[u]) gtime[e]=es[i].w;
			}
			continue;
		}
		if(ele[u].size()<ele[v].size()) swap(u,v);
		p[v] = {u,es[i].w};
		maxd[u] = max({maxd[u],deg[es[i].a],deg[es[i].b],maxd[v]});
		cyc[u] = cyc[u]|cyc[v];
		if(maxd[u]>2 || cyc[u]){
			if(!gtime[u]){
				for(auto e : ele[u]) gtime[e]=es[i].w;
			}
			if(!gtime[v]){
				for(auto e : ele[v]) gtime[e]=es[i].w;
			}
		}
		for(auto e : ele[v]) ele[u].push_back(e);
	}
}

int getMinimumFuelCapacity(int X, int Y) {
	int mc=0;	
	int x = X;
	int y = Y;
	while(x!=y){
		if(ele[x].size()<ele[y].size()) swap(x,y);
		mc = max(mc,p[y].second);
		y = p[y].first;
	}
	if(gtime[X]==-1 || gtime[Y]==-1) return -1;
	return max({mc,gtime[X],gtime[Y]});
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 544 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 39 ms 15212 KB Output is correct
10 Correct 54 ms 18120 KB Output is correct
11 Correct 48 ms 17876 KB Output is correct
12 Correct 50 ms 18928 KB Output is correct
13 Correct 42 ms 16324 KB Output is correct
14 Correct 46 ms 15300 KB Output is correct
15 Correct 131 ms 23376 KB Output is correct
16 Correct 134 ms 22900 KB Output is correct
17 Correct 135 ms 23856 KB Output is correct
18 Correct 92 ms 21036 KB Output is correct
19 Incorrect 58 ms 7300 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 544 KB Output is correct
3 Incorrect 85 ms 18020 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 544 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 1 ms 344 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 544 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 39 ms 15212 KB Output is correct
10 Correct 54 ms 18120 KB Output is correct
11 Correct 48 ms 17876 KB Output is correct
12 Correct 50 ms 18928 KB Output is correct
13 Correct 42 ms 16324 KB Output is correct
14 Correct 46 ms 15300 KB Output is correct
15 Correct 131 ms 23376 KB Output is correct
16 Correct 134 ms 22900 KB Output is correct
17 Correct 135 ms 23856 KB Output is correct
18 Correct 92 ms 21036 KB Output is correct
19 Incorrect 85 ms 18020 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -