結果

問題 No.1473 おでぶなおばけさん
ユーザー 👑 kmjpkmjp
提出日時 2021-04-10 01:17:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 2,063 bytes
コンパイル時間 4,071 ms
コンパイル使用メモリ 214,964 KB
実行使用メモリ 12,768 KB
最終ジャッジ日時 2023-09-07 20:16:07
合計ジャッジ時間 8,420 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,948 KB
testcase_01 AC 4 ms
7,988 KB
testcase_02 AC 75 ms
12,660 KB
testcase_03 AC 66 ms
11,868 KB
testcase_04 AC 38 ms
10,404 KB
testcase_05 AC 17 ms
8,788 KB
testcase_06 AC 73 ms
12,220 KB
testcase_07 AC 81 ms
12,460 KB
testcase_08 AC 82 ms
12,768 KB
testcase_09 AC 80 ms
12,768 KB
testcase_10 AC 41 ms
10,656 KB
testcase_11 AC 41 ms
11,692 KB
testcase_12 AC 42 ms
11,160 KB
testcase_13 AC 27 ms
9,980 KB
testcase_14 AC 21 ms
9,332 KB
testcase_15 AC 37 ms
10,808 KB
testcase_16 AC 40 ms
10,392 KB
testcase_17 AC 6 ms
7,892 KB
testcase_18 AC 9 ms
8,180 KB
testcase_19 AC 44 ms
10,612 KB
testcase_20 AC 57 ms
11,484 KB
testcase_21 AC 64 ms
11,600 KB
testcase_22 AC 57 ms
12,288 KB
testcase_23 AC 48 ms
11,388 KB
testcase_24 AC 46 ms
11,428 KB
testcase_25 AC 65 ms
12,204 KB
testcase_26 AC 64 ms
12,372 KB
testcase_27 AC 24 ms
9,592 KB
testcase_28 AC 80 ms
12,456 KB
testcase_29 AC 60 ms
11,488 KB
testcase_30 AC 71 ms
11,912 KB
testcase_31 AC 65 ms
12,544 KB
testcase_32 AC 61 ms
12,404 KB
testcase_33 AC 55 ms
11,396 KB
testcase_34 AC 27 ms
9,808 KB
testcase_35 AC 30 ms
10,160 KB
testcase_36 AC 45 ms
10,860 KB
testcase_37 AC 54 ms
11,168 KB
testcase_38 AC 12 ms
8,480 KB
testcase_39 AC 41 ms
10,508 KB
testcase_40 AC 40 ms
10,368 KB
testcase_41 AC 37 ms
10,412 KB
testcase_42 AC 38 ms
10,524 KB
testcase_43 AC 41 ms
11,376 KB
testcase_44 AC 41 ms
11,316 KB
testcase_45 AC 42 ms
11,344 KB
testcase_46 AC 56 ms
11,128 KB
testcase_47 AC 71 ms
11,936 KB
testcase_48 AC 62 ms
11,340 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void solve()’ 内:
main.cpp:73:18: 警告: ‘W’ may be used uninitialized [-Wmaybe-uninitialized]
   73 |         cout<<W<<" "<<dp[N-1]<<endl;
      |                  ^~~
main.cpp:51:13: 備考: ‘W’ はここで定義されています
   51 |         int W;
      |             ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
int S[101010],T[101010],D[101010];
pair<int,int> CE[101010];
vector<pair<int,int>> E[101010];
int dp[101010];

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit(int num=um) {int i; FOR(i,num) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<101010> uf;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>S[i]>>T[i]>>D[i];
		S[i]--;
		T[i]--;
		CE[i]={-D[i],i};
		E[S[i]].push_back({T[i],D[i]});
		E[T[i]].push_back({S[i],D[i]});
	}
	sort(CE,CE+M);
	int W;
	FOR(i,M) {
		x=CE[i].second;
		uf(S[x],T[x]);
		if(uf[0]==uf[N-1]) {
			W=D[x];
			break;
		}
	}
	
	FOR(i,N) dp[i]=1<<20;
	dp[0]=0;
	queue<int> Q;
	Q.push(0);
	while(Q.size()) {
		int cur=Q.front();
		Q.pop();
		FORR2(e,c,E[cur]) if(c>=W&&dp[e]>dp[cur]+1) {
			dp[e]=dp[cur]+1;
			Q.push(e);
		}
	}
	cout<<W<<" "<<dp[N-1]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0