結果

問題 No.1382 Travel in Mitaru city
ユーザー onsen_manjuuuonsen_manjuuu
提出日時 2021-02-07 21:01:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,440 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 182,652 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2023-09-17 19:57:13
合計ジャッジ時間 10,240 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 62 ms
6,480 KB
testcase_08 WA -
testcase_09 AC 84 ms
7,268 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 146 ms
11,012 KB
testcase_29 AC 143 ms
10,816 KB
testcase_30 AC 129 ms
10,724 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 85 ms
9,068 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 AC 4 ms
4,376 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 19 ms
4,380 KB
testcase_64 AC 6 ms
4,380 KB
testcase_65 AC 2 ms
4,376 KB
testcase_66 AC 4 ms
4,380 KB
testcase_67 AC 5 ms
4,380 KB
testcase_68 AC 8 ms
4,380 KB
testcase_69 AC 4 ms
4,380 KB
testcase_70 AC 10 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:57:22: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   57 |                 auto [from, to, cost] = edge[i];
      |                      ^

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pint = pair<int,int>;

#pragma region UnionFind
#define UNIONFIND
class UnionFind{
  private:
	vector<int> data;
  public:
	UnionFind(int n) : data(n,-1) {}
	int root(int i) { return data[i] < 0 ? i : data[i] = root(data[i]); }
	int size(int i) { return -data[root(i)]; }
	bool same(int x, int y) {return root(x) == root(y); }
	bool connected() {return size(0) == (int)data.size(); }

	bool unit(int i,int j){
		i = root(i);
		j = root(j);
		if(i != j){
			data[i] += data[j];
			data[j] = i;
		}
		return i != j;
	}
};
#pragma endregion
// #include"debug.hpp"

int main()
{
	int n, m, s, t; cin >> n >> m >> s >> t;
	s--,t--;
	vector<int> p(n);
	vector<vector<int>> hen(n);
	vector<tuple<int,int,int>> edge;
	for(auto &i : p) cin >> i;
	UnionFind uf(n);
	for(int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		u--,v--;
		edge.emplace_back(u, v, p[v]);
		edge.emplace_back(v, u, p[u]);
	}
	sort(edge.begin(), edge.end(), [&](tuple<int,int,int>& x, tuple<int,int,int>& y){return get<2>(x) > get<2>(y);});
	int e = edge.size();
	// print(edge);


	int sum = 0;
	set<int> st;
	st.insert(s);
	int X = p[s];
	for(int i = 0; i < e; i++) {
		auto [from, to, cost] = edge[i];
		// if(uf.same(from, to)) continue;
		if(uf.same(from, s) == 1) {
			if(!st.count(to) && cost < X)sum++;
			st.insert(to);
		}
		uf.unit(from, to);
		X = min(cost, X);
	}
	cout << sum << endl;
}
0