結果

問題 No.1382 Travel in Mitaru city
ユーザー kotatsugamekotatsugame
提出日時 2021-02-07 21:26:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 1,392 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 77,948 KB
実行使用メモリ 11,268 KB
最終ジャッジ日時 2023-09-17 20:30:25
合計ジャッジ時間 9,509 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,416 KB
testcase_01 AC 3 ms
6,528 KB
testcase_02 AC 3 ms
6,416 KB
testcase_03 AC 3 ms
6,500 KB
testcase_04 AC 3 ms
6,484 KB
testcase_05 AC 3 ms
6,500 KB
testcase_06 AC 57 ms
8,092 KB
testcase_07 AC 45 ms
7,580 KB
testcase_08 AC 25 ms
7,188 KB
testcase_09 AC 62 ms
8,124 KB
testcase_10 AC 59 ms
7,984 KB
testcase_11 AC 90 ms
9,040 KB
testcase_12 AC 92 ms
9,068 KB
testcase_13 AC 96 ms
9,244 KB
testcase_14 AC 83 ms
9,028 KB
testcase_15 AC 88 ms
9,132 KB
testcase_16 AC 141 ms
10,872 KB
testcase_17 AC 142 ms
10,888 KB
testcase_18 AC 144 ms
10,912 KB
testcase_19 AC 142 ms
10,872 KB
testcase_20 AC 141 ms
10,904 KB
testcase_21 AC 140 ms
10,976 KB
testcase_22 AC 147 ms
10,976 KB
testcase_23 AC 147 ms
10,876 KB
testcase_24 AC 150 ms
10,980 KB
testcase_25 AC 144 ms
10,832 KB
testcase_26 AC 137 ms
11,016 KB
testcase_27 AC 135 ms
10,940 KB
testcase_28 AC 136 ms
10,832 KB
testcase_29 AC 136 ms
10,884 KB
testcase_30 AC 131 ms
10,980 KB
testcase_31 AC 108 ms
10,452 KB
testcase_32 AC 129 ms
11,248 KB
testcase_33 AC 118 ms
10,836 KB
testcase_34 AC 81 ms
9,292 KB
testcase_35 AC 55 ms
8,312 KB
testcase_36 AC 90 ms
10,400 KB
testcase_37 AC 17 ms
7,164 KB
testcase_38 AC 100 ms
11,008 KB
testcase_39 AC 27 ms
7,704 KB
testcase_40 AC 77 ms
9,576 KB
testcase_41 AC 84 ms
10,048 KB
testcase_42 AC 101 ms
10,920 KB
testcase_43 AC 88 ms
10,452 KB
testcase_44 AC 37 ms
8,100 KB
testcase_45 AC 80 ms
10,080 KB
testcase_46 AC 31 ms
7,732 KB
testcase_47 AC 110 ms
11,268 KB
testcase_48 AC 76 ms
9,608 KB
testcase_49 AC 119 ms
11,224 KB
testcase_50 AC 53 ms
8,716 KB
testcase_51 AC 106 ms
10,484 KB
testcase_52 AC 128 ms
11,136 KB
testcase_53 AC 29 ms
7,600 KB
testcase_54 AC 56 ms
8,600 KB
testcase_55 AC 120 ms
10,884 KB
testcase_56 AC 41 ms
7,816 KB
testcase_57 AC 78 ms
9,400 KB
testcase_58 AC 14 ms
7,056 KB
testcase_59 AC 38 ms
8,100 KB
testcase_60 AC 118 ms
10,832 KB
testcase_61 AC 5 ms
6,492 KB
testcase_62 AC 3 ms
6,480 KB
testcase_63 AC 15 ms
6,704 KB
testcase_64 AC 7 ms
6,584 KB
testcase_65 AC 3 ms
6,548 KB
testcase_66 AC 5 ms
6,560 KB
testcase_67 AC 5 ms
6,484 KB
testcase_68 AC 8 ms
6,560 KB
testcase_69 AC 5 ms
6,720 KB
testcase_70 AC 9 ms
6,852 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:40:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   40 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank,mx;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1),mx(n_,(int)-1e9)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			mx[b]=max(mx[b],mx[a]);
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			mx[a]=max(mx[a],mx[b]);
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
int N,M,S,T;
int P[1<<17];
vector<int>G[1<<17];
int dp[1<<17];
int id[1<<17];
main()
{
	cin>>N>>M>>S>>T;
	S--,T--;
	for(int i=0;i<N;i++)cin>>P[i];
	for(int i=0;i<M;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int i=0;i<N;i++)id[i]=i;
	sort(id,id+N,[](int i,int j){return P[i]>P[j];});
	UF uf(N);
	for(int i=0;i<N;)
	{
		int j=i;
		while(j<N&&P[id[i]]==P[id[j]])j++;
		for(int k=i;k<j;k++)
		{
			int u=id[k];
			int mx=-1e9;
			for(int v:G[u])if(P[v]>P[u])mx=max(mx,uf.mx[uf.find(v)]);
			mx++;
			if(u==S)mx=0;
			uf.mx[uf.find(u)]=mx;
		}
		for(int k=i;k<j;k++)
		{
			int u=id[k];
			for(int v:G[u])if(P[v]>=P[u])uf.unite(u,v);
		}
		i=j;
	}
	cout<<uf.mx[uf.find(T)]<<endl;
}
0