結果

問題 No.1983 [Cherry 4th Tune C] 南の島のマーメイド
ユーザー 沙耶花沙耶花
提出日時 2022-06-17 22:06:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 195 ms / 4,000 ms
コード長 1,786 bytes
コンパイル時間 4,369 ms
コンパイル使用メモリ 258,608 KB
実行使用メモリ 43,460 KB
最終ジャッジ日時 2024-04-17 14:03:15
合計ジャッジ時間 11,072 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 8 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 87 ms
13,472 KB
testcase_14 AC 105 ms
16,296 KB
testcase_15 AC 108 ms
16,560 KB
testcase_16 AC 48 ms
11,904 KB
testcase_17 AC 108 ms
17,408 KB
testcase_18 AC 95 ms
16,600 KB
testcase_19 AC 144 ms
22,096 KB
testcase_20 AC 96 ms
15,728 KB
testcase_21 AC 104 ms
18,156 KB
testcase_22 AC 132 ms
21,888 KB
testcase_23 AC 186 ms
24,944 KB
testcase_24 AC 195 ms
25,184 KB
testcase_25 AC 189 ms
25,248 KB
testcase_26 AC 173 ms
25,080 KB
testcase_27 AC 186 ms
25,196 KB
testcase_28 AC 181 ms
25,176 KB
testcase_29 AC 178 ms
25,100 KB
testcase_30 AC 192 ms
25,188 KB
testcase_31 AC 175 ms
25,064 KB
testcase_32 AC 175 ms
25,052 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 52 ms
11,136 KB
testcase_35 AC 134 ms
40,832 KB
testcase_36 AC 114 ms
18,944 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 35 ms
5,376 KB
testcase_39 AC 134 ms
43,460 KB
testcase_40 AC 110 ms
21,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

template< typename G >
struct LowLink {
  const G &g;
  vector< int > used, ord, low;
  vector< int > articulation;
  vector< pair< int, int > > bridge;
 
  LowLink(const G &g) : g(g) {}
 
  int dfs(int idx, int k, int par) {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];
    bool is_articulation = false;
    int cnt = 0;
    for(auto &to : g[idx]) {
      if(!used[to]) {
        ++cnt;
        k = dfs(to, k, idx);
        low[idx] = min(low[idx], low[to]);
        is_articulation |= ~par && low[to] >= ord[idx];
        if(ord[idx] < low[to]) bridge.emplace_back(minmax(idx, (int) to));
      } else if(to != par) {
        low[idx] = min(low[idx], ord[to]);
      }
    }
    is_articulation |= par == -1 && cnt > 1;
    if(is_articulation) articulation.push_back(idx);
    return k;
  }
 
  virtual void build() {
    used.assign(g.size(), 0);
    ord.assign(g.size(), 0);
    low.assign(g.size(), 0);
    int k = 0;
    for(int i = 0; i < g.size(); i++) {
      if(!used[i]) k = dfs(i, k, -1);
    }
  }
};

int main(){
	
	int N,M,Q;
	cin>>N>>M>>Q;
	vector<int> u(M),v(M);
	rep(i,M){
		scanf("%d %d",&u[i],&v[i]);
		u[i]--,v[i]--;
	}
	vector<vector<int>> E(N);
	rep(i,M){
		E[u[i]].push_back(v[i]);
		E[v[i]].push_back(u[i]);
	}
	
	LowLink<vector<vector<int>>> L(E);
	L.build();
	
	dsu D(N);
	rep(i,M){
		if(L.ord[u[i]]<L.low[v[i]])D.merge(u[i],v[i]);
		if(L.ord[v[i]]<L.low[u[i]])D.merge(u[i],v[i]);
	}
	
	rep(_,Q){
		int x,y;
		scanf("%d %d",&x,&y);
		x--,y--;
		if(D.same(x,y))printf("Yes\n");
		else printf("No\n");
	}
	
	
    return 0;
}
0