結果

問題 No.1244 Black Segment
ユーザー leaf_1415leaf_1415
提出日時 2020-10-02 22:52:11
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,621 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 80,176 KB
実行使用メモリ 15,372 KB
最終ジャッジ日時 2023-09-24 22:24:38
合計ジャッジ時間 3,829 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,852 KB
testcase_01 AC 4 ms
5,696 KB
testcase_02 AC 3 ms
5,720 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 3 ms
5,700 KB
testcase_07 WA -
testcase_08 AC 4 ms
5,764 KB
testcase_09 AC 3 ms
5,700 KB
testcase_10 WA -
testcase_11 AC 4 ms
5,768 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 5 ms
6,040 KB
testcase_18 AC 34 ms
8,700 KB
testcase_19 AC 54 ms
10,380 KB
testcase_20 AC 55 ms
10,172 KB
testcase_21 AC 44 ms
9,488 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 62 ms
15,352 KB
testcase_28 WA -
testcase_29 AC 52 ms
10,388 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 58 ms
12,652 KB
testcase_34 AC 65 ms
11,136 KB
testcase_35 AC 51 ms
12,160 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, m, a, b;
vector<llint> G[100005];
bool used[100005], used2[100005], par[100005];

llint dfs(int v, int p)
{
	used[v] = true;
	llint ret = 0;
	for(int i = 0; i < G[v].size(); i++){
		llint u = G[v][i];
		if(u == p) continue;
		ret++;
		par[v] = !par[v], par[u] = !par[u];
		if(!used[u]) ret += dfs(u, v);
	}
	return ret;
}

vector<llint> vec;
void dfs2(int v)
{
	used2[v] = true;
	if(par[v]) vec.push_back(v);
	for(int i = 0; i < G[v].size(); i++){
		if(used2[G[v][i]]) continue;
		dfs2(G[v][i]);
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> a >> b;
	llint l, r;
	for(int i = 1; i <= m; i++){
		cin >> l >> r;
		G[l-1].push_back(r);
		G[r].push_back(l-1);
	}
	
	llint ans = inf;
	for(int i = 0; i < a; i++){
		if(used[i]) continue;
		llint res = dfs(i, -1);
		vec.clear(), dfs2(i);
		if(vec.size() != 2) continue;
		sort(vec.begin(), vec.end());
		if(vec[0] < a && vec[1] >= b) ans = min(ans, res);
	}
	if(ans > inf/2) cout << -1 << endl;
	else cout << ans << endl;
	
	return 0;
}
0