結果

問題 No.1382 Travel in Mitaru city
ユーザー kotatsugamekotatsugame
提出日時 2021-02-07 21:22:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,381 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 78,620 KB
実行使用メモリ 11,452 KB
最終ジャッジ日時 2023-09-17 20:26:20
合計ジャッジ時間 9,252 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,596 KB
testcase_01 AC 3 ms
6,480 KB
testcase_02 AC 3 ms
6,424 KB
testcase_03 AC 3 ms
6,540 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 56 ms
8,160 KB
testcase_07 AC 45 ms
7,684 KB
testcase_08 AC 25 ms
7,244 KB
testcase_09 AC 60 ms
8,172 KB
testcase_10 AC 58 ms
7,996 KB
testcase_11 WA -
testcase_12 AC 89 ms
9,036 KB
testcase_13 AC 96 ms
9,424 KB
testcase_14 AC 84 ms
9,008 KB
testcase_15 AC 87 ms
9,128 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 133 ms
10,900 KB
testcase_19 WA -
testcase_20 AC 141 ms
10,856 KB
testcase_21 AC 138 ms
10,892 KB
testcase_22 AC 135 ms
11,004 KB
testcase_23 AC 134 ms
10,852 KB
testcase_24 AC 139 ms
10,940 KB
testcase_25 AC 142 ms
11,004 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 90 ms
10,312 KB
testcase_37 AC 17 ms
7,108 KB
testcase_38 AC 100 ms
11,160 KB
testcase_39 AC 27 ms
7,692 KB
testcase_40 AC 75 ms
9,624 KB
testcase_41 AC 84 ms
10,156 KB
testcase_42 AC 101 ms
10,888 KB
testcase_43 AC 88 ms
10,364 KB
testcase_44 AC 36 ms
8,076 KB
testcase_45 AC 80 ms
9,848 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 103 ms
10,480 KB
testcase_52 AC 123 ms
11,232 KB
testcase_53 AC 28 ms
7,708 KB
testcase_54 AC 55 ms
8,560 KB
testcase_55 AC 116 ms
10,972 KB
testcase_56 AC 39 ms
7,740 KB
testcase_57 AC 76 ms
9,272 KB
testcase_58 AC 14 ms
7,072 KB
testcase_59 AC 38 ms
8,104 KB
testcase_60 AC 111 ms
10,992 KB
testcase_61 WA -
testcase_62 AC 3 ms
6,624 KB
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 idx=0;idx<N;idx++)
	{
		int u=id[idx];
		for(int v:G[u])if(P[v]>P[u])uf.unite(u,v);
		int mx=uf.mx[uf.find(u)];
		mx++;
		if(u==S)mx=0;
		uf.mx[uf.find(u)]=mx;
		if(idx+1<N&&P[id[idx]]>P[id[idx+1]])
		{
			for(int i=idx;i>=0&&P[id[idx]]==P[id[i]];i--)
			{
				for(int v:G[id[i]])if(P[v]==P[id[i]])uf.unite(v,id[i]);
			}
		}
	}
	cout<<uf.mx[uf.find(T)]<<endl;
}
0