結果

問題 No.1983 [Cherry 4th Tune C] 南の島のマーメイド
ユーザー 沙耶花
提出日時 2022-06-17 22:06:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 194 ms / 4,000 ms
コード長 1,786 bytes
コンパイル時間 4,113 ms
コンパイル使用メモリ 254,880 KB
最終ジャッジ日時 2025-01-29 22:03:28
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:58:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   58 |                 scanf("%d %d",&u[i],&v[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:78:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   78 |                 scanf("%d %d",&x,&y);
      |                 ~~~~~^~~~~~~~~~~~~~~

ソースコード

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