Problem:
Problem F: 自転車
Problem Statement
菊地君は、大の自転車好きである。今日も彼は、お気に入りの自転車に乗ってサイクリングロードへと走り出そうとしている。
彼が住む地域には、N個の町が存在する。各町を町1、町2...、町Nと呼ぶこととする。彼が住む町は、町1である。この地域には、サイクリングを趣味としている人が多く、最近では頻繁に町と町を結ぶサイクリングロードが作られている。サイクリングロードを使うと、2つの町を双方向に移動できる。入力では、どの町とどの町が新しくサイクリングロードで繋がれたかが時系列順に入力される。
菊地君は、新しいサイクリングロードが1つ完成したときに、次に示す条件を満たすときだけサイクリングに出かける。まず、サイクリング中に同じ風景を何回も見るのはつまらないため、
同じ町や同じサイクリングロードを2回以上通らない
ような道順である必要がある。サイクリングの終了時には家に帰るようにしたいため、
スタート地点は町1で、ゴール地点は町1
である必要がある。そして、
完成した最新のサイクリングロード1つを必ず走らなければならない
。また、全ての町やサイクリングロードを通る必要はない。
完成したサイクリングロードが時系列順に与えられるので、各サイクリングロードが完成した時点で、菊地君がサイクリングできるかどうかを答えよ。
Input
各データセットは、以下の形式で入力される。
N M
a1 b1
a2 b2
...
aM bM
入力値は、全て整数である。Nは町の数、Mは作られるサイクリングロードの数である。
始め、どの町と町の間にもサイクリングロードは作られていない
。aiとbiは、町aiと町biを繋ぐサイクリングロードが、i番目に完成することを表わしている。
Constraints
3 <= N <= 100
1 <= M <= N * (N - 1) / 2
1 <= ai, bi <= N
ai ≠ bi
同じ町間を繋ぐサイクリングロードは、2回以上現れない。
Output
M行にわたって、問題文に指定された条件で菊地君がサイクリングできるかどうかを答えよ。出力のi行目は、{(a1, b1), (a2, b2), ..., (ai, bi)}のサイクリングロードを使って、サイクリングできるかどうかを出力する。サイクリングできるならば"Yes"、できないならば"No"と出力せよ。
Sample Input 1
3 3
1 2
2 3
3 1
Output for the Sample Input 1
No
No
Yes
始めの2つのサイクリングロードだけでは、自分の町に戻ることができないためNoとなる。(3, 1)が追加されたときは、新しいサイクリングロード(3と1の道)を通りつつ、自分の町に戻ることができるためYesとなる。
Sample Input 2
4 4
1 2
2 3
2 4
3 4
Output for the Sample Input 2
No
No
No
No
どの段階においても、自分の町に戻るのに、同じ町・サイクリングロードを必ず2回以上通らなければならないため、全てNoである。

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<typename T>
struct Max_Flow{
    struct edge{
        int to; T cap; int rev;
        edge(int to, T cap, int rev) : to(to), cap(cap), rev(rev) {}
    };

    vector<vector<edge>> es;
    vector<bool> used;
    const T INF_T;

    Max_Flow(int n) : INF_T(numeric_limits<T>::max()){
        es.resize(n), used.resize(n);
    }

    void add_edge(int from, int to, T cap, bool directed = true){
        es[from].eb(to, cap, sz(es[to]));
        es[to].eb(from, directed? 0 : cap, sz(es[from])-1);
    }

    T dfs(int now, int t, T flow){
        if(now == t) return flow;
        used[now] = true;
        for(auto &e: es[now]){
            if(!used[e.to] && e.cap > 0){
                T f = dfs(e.to, t, min(flow, e.cap));
                if(f > 0){
                    e.cap -= f;
                    es[e.to][e.rev].cap += f;
                    return f;
                }
            }
        }
        return 0;
    }

    T max_flow(int s, int t){
        T flow = 0;
        for(;;){
            fill(all(used), false);
            T f = dfs(s, t, INF_T);
            if(f == 0) return flow;
            flow += f;
        }
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    int u[M], v[M];
    rep(i, M){
        Max_Flow<int> G(2*N+1);
        int s = N, t = 2*N;
        cin >> u[i] >> v[i]; u[i]--, v[i]--;
        rep(j, N) G.add_edge(j, N+j, 1);
        rep(j, i){
            G.add_edge(N+u[j], v[j], 1), G.add_edge(N+v[j], u[j], 1);
        }
        G.add_edge(N+u[i], t, 1), G.add_edge(N+v[i], t, 1);
        if(G.max_flow(s, t) == 2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}
accuracy: 1
time_ms: 800
memory_kb: 3356
final_rank: 12

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
template <typename T>
struct FordFulkerson {
  struct Edge {
    int dst, rev;
    T cap;
    Edge(int dst, T cap, int rev) : dst(dst), cap(cap), rev(rev) {}
  };

  vector<vector<Edge> > graph;

  FordFulkerson(int n) : graph(n), used(n, -1) {}

  void add_edge(int src, int dst, T cap) {
    graph[src].emplace_back(dst, cap, graph[dst].size());
    graph[dst].emplace_back(src, 0, graph[src].size() - 1);
  }

  T maximum_flow(int s, int t, T limit) {
    T res = 0;
    while (true) {
      T tmp = dfs(s, t, limit);
      ++timestamp;
      if (tmp == 0) return res;
      res += tmp;
      limit -= tmp;
    }
  }

private:
  vector<int> used;
  int timestamp = 0;

  T dfs(int ver, int t, T flow) {
    if (ver == t) return flow;
    used[ver] = timestamp;
    for (Edge &e : graph[ver]) if (used[e.dst] < timestamp && e.cap > 0) {
      T tmp = dfs(e.dst, t, min(flow, e.cap));
      if (tmp > 0) {
        e.cap -= tmp;
        graph[e.dst][e.rev].cap += tmp;
        return tmp;
      }
    }
    return 0;
  }
};

int main() {
  int n, m; cin >> n >> m;
  vector<int> a(m), b(m);
  REP(i, m) {
    cin >> a[i] >> b[i]; --a[i]; --b[i];
    FordFulkerson<int> ff(n * 2 + 1);
    REP(i, n) ff.add_edge(i * 2, i * 2 + 1, 1);
    REP(j, i) {
      ff.add_edge(a[j] * 2 + 1, b[j] * 2, 1);
      ff.add_edge(b[j] * 2 + 1, a[j] * 2, 1);
    }
    ff.add_edge(a[i] * 2 + 1, n * 2, 1);
    ff.add_edge(b[i] * 2 + 1, n * 2, 1);
    cout << (ff.maximum_flow(1, n * 2, 2) == 2 ? "Yes\n" : "No\n");
  }
  return 0;
}
accuracy: 1
time_ms: 810
memory_kb: 3412
final_rank: 13

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

struct edge {
    ll to, cap, rev;
};
struct Dinic {
    vector<vector<edge>> G;
    VL level, iter;
    ll N;

    Dinic(ll size) : N(size) { init(size); };

    void init(ll size) { G.resize(N); }

    void add_edge(ll from, ll to, ll cap) {
        G[from].push_back({to, cap, (ll)G[to].size()});
        G[to].push_back({from, 0, (ll)G[from].size() - 1});
    }
    void bfs(ll s) {
        level.assign(N, -1);
        queue<ll> q;
        level[s] = 0;
        q.push(s);
        while(!q.empty()) {
            ll now = q.front();
            q.pop();
            FOREACH(e, G[now]) {
                if(e.cap > 0 && level[e.to] == -1) {
                    level[e.to] = level[now] + 1;
                    q.push(e.to);
                }
            }
        }
    }

    ll dfs(ll now, ll t, ll f) {
        if(now == t) return f;
        for(ll &i = iter[now]; i < G[now].size(); i++) {
            edge &e = G[now][i];
            if(e.cap > 0 && level[now] < level[e.to]) {
                ll d = dfs(e.to, t, min(f, e.cap));
                if(d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    ll max_flow(ll s, ll t) {
        ll flow = 0;
        while(1) {
            bfs(s);
            if(level[t] < 0) return flow;
            iter.assign(N, 0);
            ll f;
            while((f = dfs(s, t, LINF)) > 0) {
                flow += f;
            }
        }
    }
};

signed main() {
    LCIN(N, M);
    VL a(M), b(M);
    REP(i, M) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        Dinic mf(2*N + 1);
        REP(j,N) mf.add_edge(j,j+N,1);
        REP(j, i) {
            mf.add_edge(a[j]+N, b[j], 1);
            mf.add_edge(b[j]+N, a[j], 1);
        }
        mf.add_edge(a[i]+N, 2*N, 1);
        mf.add_edge(b[i]+N, 2*N, 1);
        cout << (mf.max_flow(N, 2*N) == 2 ? "Yes" : "No") << "\n";
    }
}
accuracy: 1
time_ms: 1220
memory_kb: 3780
final_rank: 18

code_snippet: // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

// Dinic を信じろ

template <typename T>
struct Edge {
    int to; T cap, cost; int rev;
    Edge(int t, T c, int r) : to(t), cap(c), rev(r) {}
    Edge(int t, T ca, T co, int r) : to(t), cap(ca), cost(co), rev(r) {}
};

template <typename T>
using Graph = vector< vector< Edge<T> > >;

template<typename T>
struct Dinic {
    int N, M;
    Graph<T> G;
    vector<int> level, iter;
    Dinic(int n, int m = 0) : N(n), M(m) {
        G.resize(N);
        level.resize(N);
        iter.resize(N);
    }
    void add_edge(int from, int to, T cost) {
        G[from].push_back(Edge<T>(to  , cost, G[to  ].size()    ));
        G[to  ].push_back(Edge<T>(from, 0.0 , G[from].size() - 1));
    }
    void readGraph() {
        for(int i=0; i<M; i++) {
            int a, b; T c;
            cin >> a >> b >> c;
            // a--; b--;
            add_edge(a, b, c);
        }
    }
    void bfs(int s) {
        fill(level.begin(), level.end(), -1);
        queue<int> que; que.push(s);
        level[s] = 0;
        while(!que.empty()) {
            int temp = que.front(); que.pop();
            for(size_t i=0; i<G[temp].size(); i++) {
                Edge<T> &e = G[temp][i];
                if(e.cap > 0 && level[e.to] < 0) {
                    level[e.to] = level[temp] + 1;
                    que.push(e.to);
                }
            }
        }
    }
    T dfs(int v, int t, T f) {
        if(v == t) return f;
        for(int &i = iter[v]; i<(int)G[v].size(); i++) {
            Edge<T> &e = G[v][i];
            if(e.cap > 0 && level[v] < level[e.to]) {
                T d = dfs(e.to, t, min(f, e.cap));
                if(d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    T max_flow(int s, int t) {
        T flow = 0.0, f;
        while(1) {
            bfs(s);
            if(level[t] < 0) return flow;
            fill(iter.begin(), iter.end(), 0);
            while( (f = dfs(s, t, INF)) > 0 ) flow += f;
        }
    }
};

// 最小流量制約付きフロー
// u から v に最小 lb, 最大 ub 流す
template<typename flow_type>
struct Dinic_lr {
    Dinic<flow_type> fl;
    int S, T;
    flow_type sum_lb;

    Dinic_lr() {}
    Dinic_lr(int N) : fl(N+2, 0), S(N), T(N+1), sum_lb(0) {}

    void add_edge(int u, int v, flow_type lb, flow_type ub) {
        assert(0 <= lb && lb <= ub);
        if(u == v || ub == 0) return;
        fl.add_edge(u, v, ub - lb);
        fl.add_edge(S, v, lb);
        fl.add_edge(u, T, lb);
        sum_lb += lb;
    }

    flow_type max_flow(int s, int t) {
        flow_type a = fl.max_flow(S, T);
        flow_type b = fl.max_flow(s, T);
        flow_type c = fl.max_flow(S, t);
        flow_type d = fl.max_flow(s, t);
        return (a + c == sum_lb && a + b == sum_lb) ? b + d : -1;
    }
};

signed main() {
    int N, M; cin >> N >> M;

    vector< pair<int, int> > edges;
    for(int i=0; i<M; i++) {
        int a, b; cin >> a >> b;
        a--; b--;

        Dinic<int> fl(2 + 2 * N);
        int source = 2*N, sink = source + 1;
        fl.add_edge(source, 2*a, 1);
        fl.add_edge(source, 2*b, 1);
        fl.add_edge(1, sink, 2);

        for(int i=0; i<N; i++) {
            fl.add_edge(2*i, 2*i + 1, 1 + (i == 0));
        }
        for(auto e : edges) {
            int u, v; tie(u, v) = e;
            fl.add_edge(2*u + 1, 2*v, 1);
            fl.add_edge(2*v + 1, 2*u, 1);
        }

        edges.emplace_back(a, b);

        int f = fl.max_flow(source, sink);
        if(f == 2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 1140
memory_kb: 3944
final_rank: 17

code_snippet: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

#include<cstring>
struct edge {
	int to, cap, rev;
};
const int mn = 300;
vector<edge> G[mn];
bool used[mn];
void add_edge(int from, int to, int cap) {
	G[from].push_back(edge{ to,cap,(int)G[to].size() });
	G[to].push_back(edge{ from,0,(int)G[from].size() - 1 });
}
int dfs(int v, int t, int f) {
	if (v == t)return f;
	used[v] = true;
	rep(i, (int)G[v].size()) {
		edge &e = G[v][i];
		if (!used[e.to] && e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, mod);
		if (f == 0)return flow;
		flow += f;
	}
}
vector<P> v;
int n, m;
bool update(int l,int r) {
	rep(i, 2 * n + 2) {
		G[i].clear();
	}
	int s = 2 * n; int t = s + 1;
	rep(i, n) {
		add_edge(i, n + i, 1);
	}
	add_edge(s, l, 1); add_edge(s, r, 1);
	add_edge(0, t, 2);
	rep(i, v.size()) {
		int le = v[i].first, ri = v[i].second;
		add_edge(le + n, ri, 1);
		add_edge(ri + n, le, 1);
	}
	int f = max_flow(s, t);
	if (f == 2)return true;
	else return false;
}

void solve() {
	cin >> n >> m;
	rep(i, m) {
		int a, b; cin >> a >> b; a--; b--;
		if (update(a,b)) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
		v.push_back({ a,b });
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}
accuracy: 1
time_ms: 420
memory_kb: 3416
final_rank: 6

code_snippet: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, M, cant, a, b; bool ok = true; vector<bool> vis; vector<vector<int> > G;
bool dfs(int pos) {
	if (pos == a || pos == b) return true;
	vis[pos] = true;
	for (int i : G[pos]) {
		if (i != cant && !vis[i] && dfs(i)) {
			return true;
		}
	}
	return false;
}
int main() {
	cin >> N >> M;
	G.resize(N);
	for (int i = 0; i < M; ++i) {
		cin >> a >> b; --a, --b;
		if (a != 0 && b != 0) {
			G[a].push_back(b);
			G[b].push_back(a);
			bool ok = true;
			for (int j = 1; j < N; ++j) {
				vis = vector<bool>(N, false);
				cant = j;
				if (!dfs(0)) {
					ok = false;
				}
			}
			cout << (ok ? "Yes" : "No") << endl;
		}
		else {
			if (a > b) swap(a, b);
			vis = vector<bool>(N, false);
			a = -1; cant = -1;
			cout << (dfs(0) ? "Yes" : "No") << endl;
			G[0].push_back(b);
			G[b].push_back(0);
		}
	}
	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 3240
final_rank: 2

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 300

enum Type{
	IN,
	OUT,
};

struct Edge{
	Edge(int arg_to,int arg_capacity,int arg_rev_index){
		to = arg_to;
		capacity = arg_capacity;
		rev_index = arg_rev_index;
	}
	int to,capacity,rev_index;
};

struct Info{
	int from,to;
};

int V;

vector<Edge> G[NUM];
int dist[NUM];
int cheked_index[NUM];
Info info[6000];

void add_edge(int from,int to,int capacity){
	G[from].push_back(Edge(to,capacity,G[to].size()));
	G[to].push_back(Edge(from,0,G[from].size()-1));
}

void bfs(int source){
	for(int i = 0; i < V; i++)dist[i] = -1;
	queue<int> Q;
	dist[source] = 0;
	Q.push(source);

	while(!Q.empty()){
		int node_id = Q.front();
		Q.pop();
		for(int i = 0; i < G[node_id].size(); i++){
			Edge &e = G[node_id][i];
			if(e.capacity > 0 && dist[e.to] < 0){
				dist[e.to] = dist[node_id]+1;
				Q.push(e.to);
			}
		}
	}
}

int dfs(int node_id,int sink,int flow){
	if(node_id == sink)return flow;

	for(int &i = cheked_index[node_id]; i < G[node_id].size(); i++){
		Edge &e = G[node_id][i];
		if(e.capacity > 0 && dist[node_id] < dist[e.to]){
			int tmp_flow = dfs(e.to,sink,min(flow,e.capacity));
			if(tmp_flow > 0){
				e.capacity -= tmp_flow;
				G[e.to][e.rev_index].capacity += tmp_flow;
				return tmp_flow;
			}
		}
	}
	return 0;
}

int max_flow(int source,int sink){
	int flow = 0,add;
	while(true){
		bfs(source);
		if(dist[sink] < 0)break;
		for(int i = 0; i < V; i++)cheked_index[i] = 0;
		while((add = dfs(source,sink,BIG_NUM)) > 0){
			flow += add;
		}
	}
	return flow;
}

int main(){

	int N,M;
	scanf("%d %d",&N,&M);

	int source = 0,sink = 2*N;
	int index_table[100][2];
	for(int i = 0; i < N; i++){
		index_table[i][IN] = 2*i;
		index_table[i][OUT] = 2*i+1;
	}

	V = 2*N+1;

	for(int i = 0; i < M; i++){
		scanf("%d %d",&info[i].from,&info[i].to);
		info[i].from--;
		info[i].to--;

		if(i == 0){
			printf("No\n");
			continue;
		}

		for(int k = 0; k < NUM; k++)G[k].clear();

		add_edge(index_table[0][IN],index_table[0][OUT],2); //行きと帰りで流量2
		for(int k = 1; k < N; k++){
			add_edge(index_table[k][IN],index_table[k][OUT],1); //各町の入次ノードと出次ノードを結ぶ
		}

		for(int k = 0; k < i; k++){
			add_edge(index_table[info[k].from][OUT],index_table[info[k].to][IN],1);
			add_edge(index_table[info[k].to][OUT],index_table[info[k].from][IN],1);
		}

		add_edge(index_table[info[i].from][OUT],sink,1);
		add_edge(index_table[info[i].to][OUT],sink,1);

		if(max_flow(source,sink) == 2){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}

	return 0;
}
accuracy: 1
time_ms: 530
memory_kb: 3336
final_rank: 9

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 300

enum Type{
	IN,
	OUT,
};

//辺を表す構造体(行先、容量、逆辺のインデックス)
struct Edge{
	Edge(int arg_to,int arg_capacity,int arg_rev_index){
		to = arg_to;
		capacity = arg_capacity;
		rev_index = arg_rev_index;
	}
	int to,capacity,rev_index;
};

struct Info{
	int from,to;
};

int V;

vector<Edge> G[NUM]; //グラフの隣接リスト表現
int dist[NUM]; //sourceからの距離
int cheked_index[NUM]; //どこまで調べ終わったか
Info info[6000];

//fromからtoへ向かう容量capacityの辺をグラフに追加する
void add_edge(int from,int to,int capacity){
	G[from].push_back(Edge(to,capacity,G[to].size()));
	G[to].push_back(Edge(from,0,G[from].size()-1)); //逆辺の、初期容量は0
}

//sourceからの最短距離をBFSで計算する
void bfs(int source){
	for(int i = 0; i < V; i++)dist[i] = -1;
	queue<int> Q;
	dist[source] = 0;
	Q.push(source);

	while(!Q.empty()){
		int node_id = Q.front();
		Q.pop();
		for(int i = 0; i < G[node_id].size(); i++){
			Edge &e = G[node_id][i];
			if(e.capacity > 0 && dist[e.to] < 0){ //辺の容量が正で、かつエッジの行先に未訪問の場合
				dist[e.to] = dist[node_id]+1;
				Q.push(e.to);
			}
		}
	}
}

//増加パスをDFSで探す
int dfs(int node_id,int sink,int flow){
	if(node_id == sink)return flow; //終点についたらflowをreturn

	for(int &i = cheked_index[node_id]; i < G[node_id].size(); i++){ //node_idから出ているエッジを調査
		Edge &e = G[node_id][i];
		if(e.capacity > 0 && dist[node_id] < dist[e.to]){ //流せる余裕があり、かつsourceからの距離が増加する方法である場合
			int tmp_flow = dfs(e.to,sink,min(flow,e.capacity)); //流せるだけ流す
			if(tmp_flow > 0){ //流せた場合
				e.capacity -= tmp_flow; //流した分、エッジの容量を削減する
				G[e.to][e.rev_index].capacity += tmp_flow; //逆辺の容量を、流した分だけ増加させる
				return tmp_flow;
			}
		}
	}
	return 0;
}


//sourceからsinkへの最大流を求める
int max_flow(int source,int sink){ //source:始点 sink:終点
	int flow = 0,add;
	while(true){ //増加パスが存在する限り、流量を追加し続ける
		bfs(source);
		if(dist[sink] < 0)break; //sourceからsinkへと辿り着く残余グラフがない、つまり増加パスが無くなった場合、break
		for(int i = 0; i < V; i++)cheked_index[i] = 0;
		while((add = dfs(source,sink,BIG_NUM)) > 0){ //増加パスが見つかる間、加算
			flow += add;
		}
	}
	return flow;
}

int main(){

	int N,M;
	scanf("%d %d",&N,&M);

	int source = 0,sink = 2*N;
	int index_table[100][2];
	for(int i = 0; i < N; i++){
		index_table[i][IN] = 2*i;
		index_table[i][OUT] = 2*i+1;
	}

	V = 2*N+1;

	for(int i = 0; i < M; i++){
		scanf("%d %d",&info[i].from,&info[i].to);
		info[i].from--;
		info[i].to--;

		if(i == 0){
			printf("No\n");
			continue;
		}

		for(int k = 0; k < NUM; k++)G[k].clear();

		add_edge(index_table[0][IN],index_table[0][OUT],2); //行きと帰りで流量2
		for(int k = 1; k < N; k++){
			add_edge(index_table[k][IN],index_table[k][OUT],1); //各町の入次ノードと出次ノードを結ぶ
		}

		//辺を張りなおす
		for(int k = 0; k < i; k++){
			add_edge(index_table[info[k].from][OUT],index_table[info[k].to][IN],1);
			add_edge(index_table[info[k].to][OUT],index_table[info[k].from][IN],1);
		}

		//最新の辺は、その両端のノードをsinkへつなぐ
		add_edge(index_table[info[i].from][OUT],sink,1);
		add_edge(index_table[info[i].to][OUT],sink,1);

		if(max_flow(source,sink) == 2){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}

	return 0;
}
accuracy: 1
time_ms: 530
memory_kb: 3300
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

// (行き先,容量,逆辺)
struct edge{ int to,cap,rev; };

const int MAX_V = 202; // TODO:initialize
const int F_INF = 191919; // TODO:initialize
vector<edge> G[MAX_V];
int level[MAX_V]; // sからの距離
int iter[MAX_V]; // どこまで調べ終わったか

void add_edge(int from, int to, int cap){
    G[from].pb({to,cap,(int)G[to].size()});
    G[to].pb({from,0,(int)G[from].size()-1});
}

void dinic_bfs(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        rep(i,G[v].size()){
            edge &e = G[v][i];
            if(e.cap>0 && level[e.to]<0){
                level[e.to] = level[v]+1;
                que.push(e.to);
            }
        }
    }
}

// 増加パスをdfsで探す
int dinic_dfs(int v, int t, int f){
    if(v==t) return f;
    for(int &i=iter[v]; i<(int)G[v].size(); ++i){
        edge &e=G[v][i];
        if(e.cap>0 && level[v]<level[e.to]){
            int d = dinic_dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// sからtへの最大流
int max_flow(int s, int t){
    int flow = 0;
    while(1){
        dinic_bfs(s);
        if(level[t]<0) return flow;
        memset(iter,0,sizeof(iter));
        int f;
        while((f=dinic_dfs(s,t,F_INF))>0) flow+=f;
    }
}

int main(){
    int n,m;
    cin >>n >>m;

    int T = 2*n;

    vector<int> a(m),b(m);
    rep(i,m){
        cin >>a[i] >>b[i];
        --a[i];
        --b[i];

        rep(j,MAX_V) G[j].clear();
        rep(j,n) add_edge(j,j+n,1);

        rep(j,i){
            add_edge(a[j]+n, b[j],1);
            add_edge(b[j]+n, a[j],1);
        }

        add_edge(a[i]+n,T,1);
        add_edge(b[i]+n,T,1);

        int f = max_flow(n,T);
        printf("%s\n", f==2?"Yes":"No");
    }

    return 0;
}
accuracy: 1
time_ms: 700
memory_kb: 3284
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

template<typename T>
class MaximumFlow{
private:
  struct edge{int to; T cap; int rev;};
  vector<vector<edge> > Graph;
  vector<int> level, iter; //s??????????????¢,???????????§????????????
  void bfs(int s){
    fill(all(level), -1);
    queue<int> q;
    level[s]=0;
    q.push(s);
    while(!q.empty()){
      int v=q.front(); q.pop();
      for(auto e : Graph[v]){
        if(e.cap>0 && level[e.to]<0){
          level[e.to] = level[v]+1;
          q.push(e.to);
        }
      }
    }
  }
  T dfs(int v, int t, T f){
    if(v==t) return f;
    for(int &i=iter[v]; i<(int)Graph[v].size(); i++){
      auto &e = Graph[v][i];
      if(e.cap>0 && level[v]<level[e.to]){
        T d = dfs(e.to, t, min(f, e.cap));
        if(d>0){
          e.cap -= d;
          Graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
public:
  MaximumFlow(int n){
    Graph = vector<vector<edge> >(n, vector<edge>());
    level = vector<int>(n);
    iter = vector<int>(n);
  }
  T max_flow(int s, int t){
    T flow=0;
    while(true){
      bfs(s);
      if(level[t] < 0) break;
      fill(all(iter), 0);
      T f;
      while( (f=dfs(s,t,INF)) > 0){
        flow += f;
      }
    }
    return flow;
  }
  void add_edge(int from, int to, T cap){
    int tos = Graph[to].size(), froms = Graph[from].size();
    Graph[from].pb(((edge){to, cap, tos}));
    Graph[to].pb(((edge){from, 0, froms}));
  }
};

int main(){
  int n,m;
  cin>>n>>m;

  vector<MaximumFlow<int>> flows(n, MaximumFlow<int>(2*n));
  rep(i,1,n) rep(j,1,n) if(i!=j) flows[i].add_edge(2*j, 2*j+1, 1);
  vector<int> f(n,0);

  rep(_,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    if(b==0) swap(a,b);
    if(f[b]<2){
      flows[b].add_edge(a*2+1,b*2,1);
      f[b] += flows[b].max_flow(1,b*2);
    }

    if(a!=0 && f[a]<1) f[a] += flows[a].max_flow(1,a*2);

    if(f[b]>=2 && (a==0 || f[a]>=1)) cout << "Yes\n";
    else cout << "No\n";

    rep(i,1,n) if(i!=b){
      flows[i].add_edge(a*2+1,b*2,1);
      flows[i].add_edge(b*2+1,a*2,1);
    }
  }

  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 34944
final_rank: 16

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct edge {
  int to, cap, rev;
  edge(){}
  edge(int to, int cap, int rev):to(to), cap(cap), rev(rev){}
};

using Graph = vector<vector<edge>>;

struct Dinic {
  Graph graph;
  vint level, iter;
  Dinic(int V):graph(V), level(V), iter(V){}
  void add_edge(int from, int to, int cap) {
    graph[from].emplace_back(to, cap, graph[to].size());
    graph[to].emplace_back(from, 0, graph[from].size()-1);
  }
  bool bfs(int s, int t) {
    fill(all(level), -1);
    level[s] = 0;
    queue<int> que({s});
    while(!que.empty()) {
      int v = que.front(); que.pop();
      rep(i, graph[v].size()) {
	edge& e = graph[v][i];
	if(e.cap > 0 && level[e.to] < 0) {
	  que.push(e.to);
	  level[e.to] = level[v]+1;
	}
      }
    }
    return ~level[t];
  }
  int dfs(int v, int t, int f) {
    if(v == t) return f;
    for(int& i = iter[v]; i < (int)graph[v].size(); i++) {
      edge& e = graph[v][i];
      if(e.cap > 0 && level[e.to] > level[v]) {
	int d = dfs(e.to, t, min(f, e.cap));
	if(d > 0) {
	  e.cap -= d;
	  graph[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }
  int max_flow(int s, int t) {
    if(s == t) return inf;
    int flow = 0;
    while(bfs(s, t)) {
      fill(all(iter), 0);
      int f; while((f=dfs(s, t, inf)) > 0) flow += f;
    }
    return flow;
  }
};

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m;
  cin >> n >> m;
  vector<Pi> vec;
  rep(i, m) {
    int a, b;
    cin >> a >> b; --a, --b;
    vec.emplace_back(a, b);
  }
  int s = 0, t = 2*n, V = t+1;
  rep(i, m) {
    Dinic graph(V);
    rep(j, n) graph.add_edge(j, n+j, 1 + (j == 0));
    rep(j, i) {
      int a, b; tie(a, b) = vec[j];
      graph.add_edge(n+a, b, 1);
      graph.add_edge(n+b, a, 1);
    }
    int a, b; tie(a, b) = vec[i];
    graph.add_edge(n+a, t, 1);
    graph.add_edge(n+b, t, 1);
    int flow = graph.max_flow(s, t);
    cout << (flow == 2 ? "Yes" : "No") << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 1070
memory_kb: 3776
final_rank: 15

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cap,rev;};//ikisaki youryou gyakuhen
class MF{//max flow
	public:
	int n;
	vector<vector<edge> >G;//[MAX];
	vector<bool>used;//[MAX];
	MF(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int from, int to, int cap){
		edge q={to,cap,int(G[to].size())};
		G[from].push_back(q);
		q={from,0,int(G[from].size()-1)};
		G[to].push_back(q);
	}
	int dfs(int v,int t, int f) {
		if(v==t)return f;
		used[v]=1;
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(used[e.to]||e.cap<=0) continue;
			int d =dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
		return 0;
	}
	int mf(int s,int t) {//from s to t,ford_fulkerson
		int flow=0,f;
		while(1){
			used=vector<bool>(n,false);
			f=dfs(s,t,inf);
			if(f==0)return flow;
			flow+=f;
		}
	}
};
int main(){
	int n,m;
	cin>>n>>m;
	vp in(m);
	rep(i,m)cin>>in[i].first>>in[i].second;
	rep(i,m){
		MF mf(n*2+1);
		rep(j,n)mf.add_edge(j,n+j,1);
		int s=n,t=n*2;
		rep(j,i){
			mf.add_edge(n+in[j].first-1,in[j].second-1,1);
			mf.add_edge(n+in[j].second-1,in[j].first-1,1);
		}
		mf.add_edge(n+in[i].first-1,t,1);
		mf.add_edge(n+in[i].second-1,t,1);
		if(mf.mf(s,t)==2)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}
accuracy: 1
time_ms: 1080
memory_kb: 3352
final_rank: 14

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;


////???????????? - ???????????????????????? O(Flow|E|)

typedef int Weight;

const Weight INF = INT_MAX/2;
const Weight ZERO = 0;
struct Edge {
	int src, dst;
	Weight weight;
	int rev;
	int id;
	Edge(int src_, int dst_, Weight weight_, const int rev_, const int id_) :
		src(src_), dst(dst_), weight(weight_), rev(rev_), id(id_) { }
	Edge(int src_, int dst_, Weight weight_, const int rev_) :
		src(src_), dst(dst_), weight(weight_), rev(rev_) { }
	Edge() :src(0), dst(0), weight(0) {
	}
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph&g, int from, int to, int cap)
{
	g[from].push_back(Edge(from, to, cap, (int)g[to].size()));
	g[to].push_back(Edge(to, from, 0, (int)g[from].size() - 1));
}

//??????????????????????????¨????¶????
void erase_edge(Graph&g, int from, int to) {
	g[from].erase(remove_if(g[from].begin(), g[from].end(), [=](const Edge&e) {return e.dst == to; }),g[from].end());
	g[to].erase(remove_if(g[to].begin(), g[to].end(), [=](const Edge&e) {return e.dst == from; }),g[to].end());
}
int dfs(vector<int>&used, Graph&g, int now, int t, int f)
{
	if (now == t) {
		return f;
	}
	used[now] = true;
	for (int i = 0; i<g[now].size(); ++i) {
		Edge &e = g[now][i];
		if (!used[e.dst] && e.weight>0) {
			int d = dfs(used, g, e.dst, t, min(f, e.weight));
			if (d > 0) {
				e.weight -= d;
				g[e.dst][e.rev].weight += d;
				return d;
			}
		}
	}
	return 0;
}
Weight fold_falc(Graph g, const int start, const int goal) {
	Weight ans = 0;
	while (1) {
		vector<int>used(g.size());
		int flow = dfs(used, g, start, goal, INF);
		if (!flow)return ans;
		else ans += flow;
	}
}

int main() {
	int N, M; cin >> N >> M;
	int start = 0;
	int in = start + 1;
	int out = in + N;
	int goal = out + N;
	Graph g(goal + 1);
	for (int i = 1; i < N; ++i) {
		add_edge(g, in + i, out + i, 1);
	}
	add_edge(g, start, out, 2);
	for (int i = 0; i < M; ++i) {
		int a, b; cin >> a >> b; a--; b--;
		add_edge(g, out + a, goal, 1);
		add_edge(g, out + b, goal, 1);
		int flow = fold_falc(g, start, goal);
		bool ok = flow >= 2;
		if (ok) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
		erase_edge(g, out + a, goal);
		erase_edge(g, out + b, goal);
		add_edge(g, out + a, in + b, 1);
		add_edge(g, out + b, in + a, 1);
	}
	return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 3860
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
const int INF = 1000000000;
struct Dinic{
    struct Edge{
        int dst, cap, rev;
        Edge(){}
        Edge(int d, int c, int r) :
            dst(d), cap(c), rev(r) {}
    };
    typedef vector<Edge> Node;
    typedef vector<Node> Graph;

    Graph G;
    vector<int> level;
    vector<int> iter;

    void bfs(int s){
        level.assign(G.size(), -1);
        queue<int> que;
        que.push(s);
        level[s] = 0;
        while(!que.empty()){
            int v = que.front(); que.pop();
            for(const auto& e : G[v]){
                if(e.cap > 0 && level[e.dst] < 0){
                    level[e.dst] = level[v] + 1;
                    que.push(e.dst);
                }
            }
        }
    }

    int dfs(int v, int t, int f){
        if(v == t) return f;
        for(int& i = iter[v]; i < G[v].size(); i++){
            Edge& e = G[v][i];
            if(e.cap > 0 && level[v] < level[e.dst]){
                int d = dfs(e.dst, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.dst][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    Dinic(int N) : G(N), level(N), iter(N) {}

    void add_edge(int src, int dst, int cap){
         // printf("+ %d -> %d : %d\n", src, dst, cap);
        G[src].push_back(Edge(dst, cap, G[dst].size()));
        G[dst].push_back(Edge(src, 0, G[src].size() - 1));
    }
    void erase_edge(int u, int v){
        assert(G[u].back().dst == v);
        assert(G[v].back().dst == u);
         // printf("- %d -> %d\n", u, v);
        G[u].erase(G[u].begin() + G[u].size() - 1);
        G[v].erase(G[v].begin() + G[v].size() - 1);
    }

    int max_flow(int src, int dst){
        Graph tmpG = G;
        int flow = 0;
        // printf("flow %d -> %d : ", src, dst);
        while(true){
            bfs(src);
            if(level[dst] < 0) break;
            iter.assign(G.size(), 0);
            while(true){
                int f = dfs(src, dst, INF);
                if(f <= 0) break;
                flow += f;
            }
        }
        // printf(" %d \n", flow);
        G = tmpG;
        return flow;
    }
};

int main(){
    int N, M;
    while(cin >> N >> M){
        Dinic solver(2 * N + 1);
        const int src = 0;
        const int dst = 2 * N;
        REP(i, N) solver.add_edge(2 * i, 2 * i + 1, (i == 0 ? 2 : 1));
        REP(i, M) {
            int a, b;
            cin >> a >> b;
            a--; b--;
            solver.add_edge(2 * a + 1, dst, 1);
            solver.add_edge(2 * b + 1, dst, 1);
            int f = (solver.max_flow(src, dst));
            // cout << "f = " << f << endl;
            if(f == 2){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
            solver.erase_edge(2 * b + 1, dst);
            solver.erase_edge(2 * a + 1, dst);
            solver.add_edge(2 * a + 1, 2 * b, 1);
            solver.add_edge(2 * b + 1, 2 * a, 1);
        }
    }
    return 0;
}
accuracy: 1
time_ms: 370
memory_kb: 1664
final_rank: 5

code_snippet: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;

#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



struct Edge {
    int rev, from, to, cap, icap, flow;
    Edge() {}
    Edge(int r, int f, int t, int c) : rev(r), from(f), to(t), cap(c), icap(c), flow(0) {}
};

const int MAX_V = 300;
const int INF = 1<<29;
struct Graph {
    int V,E;
    vector<Edge> list[MAX_V];
    
    Graph(int n = 0) : V(n), E(0) {}
    void init(int n = 0) {V = n; E = 0; for (int i = 0; i < MAX_V; ++i) list[i].clear();}
    void resize(int n = 0) {V = n;}
    void reset() {for (int i = 0; i < V; ++i) for (int j = 0; j < list[i].size(); ++j) list[i][j].cap = list[i][j].icap;}    
    inline vector<Edge>& operator [] (int i) {return list[i];}
    
    void addedge(int from, int to, int cap) {
        if (cap > 0) {
            ++E;
            list[from].push_back(Edge(list[to].size(), from, to, cap));
            list[to].push_back(Edge(list[from].size()-1, to, from, 0));
        }
    }
    
    Edge &redge(Edge e) {
        if (e.from != e.to) return list[e.to][e.rev];
        else return list[e.to][e.rev+1];
    }
};

Graph G;


// &#201;O&#201;&#226;&#201;t&#199;&#195;&#201;f&#201;o&#201;b&#201;N&#232;o&#243;&#213;
// &#237;&#160;&#232;&#204;
ostream& operator << (ostream& s, const Edge& E) {
    return s << E.from << "->" << E.to << '(' << E.cap << ')';
}

ostream& operator << (ostream& s, const Graph& G) {
    for (int i = 0; i < G.V; ++i) {s << i << " : " << G.list[i];}
    return s;
}

int level[MAX_V];
int iter[MAX_V];

void dibfs(Graph &G, int s) {
    memset(level, -1, sizeof(level));
    level[s] = 0;
    queue<int> que;
    que.push(s);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int i = 0; i < G[v].size(); ++i) {
            Edge &e = G[v][i];
            if (level[e.to] < 0 && e.cap > 0) {
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

int didfs(Graph &G, int v, int t, int f) {
    if (v == t) return f;
    for(int &i = iter[v]; i < G[v].size(); ++i) {
        Edge &e = G[v][i], &re = G.redge(e);
        if (level[v] < level[e.to] && e.cap > 0) {
            int d = didfs(G, e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                re.cap += d;
                return d;
            }
        }
    }
    return 0;
}

int Dinic(Graph &G, int s, int t) {
    int res = 0;
    while (true) {
        dibfs(G, s);
        if (level[t] < 0) return res;
        memset(iter, 0, sizeof(iter));
        int flow;
        while ((flow = didfs(G, s, t, INF)) > 0) {
            res += flow;
        }
    }
}



int N, M;
int a, b;

int main() {
	while (cin >> N >> M) {
		G.init(N*2+1);
		G.addedge(0, N, 2);
		for (int i = 1; i < N; ++i) G.addedge(i, i+N, 1);
		int s = 0, t = N*2;

		for (int i = 0; i < M; ++i) {
			cin >> a >> b; --a; --b;

			Graph tG = G;
			tG.addedge(a+N, t, 1); tG.addedge(b+N, t, 1);

			//COUT(tG);
	
			int res = Dinic(tG, s, t);

			//COUT(res);

			if (res >= 2) cout << "Yes" << endl;
			else cout << "No" << endl;

			//if (b != 0) 
				G.addedge(a+N, b, 1);
			//if (a != 0) 
				G.addedge(b+N, a, 1);
		}
	}
    
    return 0;
}
accuracy: 1
time_ms: 540
memory_kb: 2364
final_rank: 7

code_snippet: #include<algorithm>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<stack>
#include<sstream>
#include<complex>

#define pb push_back
#define clr clear()
#define sz size()
#define fs first
#define sc second

#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define rrep(i,a) for(int i=(int)(a)−1;i>=0;i−−)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)−(b)) < EPS)
#define INIT(a) memset(a,0,sizeof(a))

using namespace std;
typedef double D;
typedef pair<D,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const D EPS = 1e-7;
const D INF = 1e9;
const D PI = acos(-1);

//辺の定義。必要に応し&#12441;て削る。
struct edge{
  int from,to,cap,rev;
  edge(int a=0,int b=0,int d=0,int e=0):from(a),to(b),cap(d),rev(e){}
};
int v; //ク&#12441;ラフの頂点数
vector<edge> G[210]; //ク&#12441;ラフの隣接リスト表現

//辺の追加。2つ目の辺の追加はフローアルコ&#12441;リス&#12441;ムの残余ク&#12441;ラフ用。 
void AddEdge(int s,int g,int p){
  G[s].pb(edge(s,g,p,G[g].sz));
  G[g].pb(edge(g,s,0,G[s].sz-1));
}

int level[210]; //まて&#12441;の距離 s
int iter[210]; //と&#12441;こまて&#12441;調へ&#12441;終わったか

void bfs(int s){
  memset(level,-1,sizeof(level));
  level[s] = 0;
  queue<int> q;
  q.push(s);
  while(q.sz){
    int u = q.front(); q.pop();
    rep(i,G[u].sz){
      edge &e = G[u][i];
      if(e.cap > 0 && level[e.to] < 0){
	level[e.to] = level[u] + 1;
	q.push(e.to);
      }
    }
  }
}

int dfs(int u, int t, int f){
  if(u==t)return f;
  for(int &i = iter[u];i<(int)G[u].sz;i++){
    edge &e = G[u][i];
    if(e.cap > 0 && level[u] < level[e.to]){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int dinic(int s, int t){
  int res = 0;
  for(;;){
    bfs(s);
    if(level[t]<0)return res;
    INIT(iter);
    int f;
    while((f=dfs(s,t,INF))>0)res += f;
  }
}

int n,m;
int a[10010],b[10010];

int main(){
  cin >> n >> m;
  v = 2*n + 1;

  rep(i,m){
    cin >> a[i] >> b[i]; a[i]--; b[i]--;
    rep(j,v)G[j].clr;

    rep(j,n)AddEdge(2*j,2*j+1,1);
    rep(j,i){
      AddEdge(2*a[j]+1,2*b[j],1);
      AddEdge(2*b[j]+1,2*a[j],1);
    }
    AddEdge(2*a[i]+1,v-1,1);
    AddEdge(2*b[i]+1,v-1,1);

    int flow = dinic(1,v-1);
    if(flow==2)cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}
accuracy: 1
time_ms: 820
memory_kb: 1600
final_rank: 11

code_snippet: #include<algorithm>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<stack>
#include<sstream>
#include<complex>

#define pb push_back
#define clr clear()
#define sz size()
#define fs first
#define sc second

#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define rrep(i,a) for(int i=(int)(a)−1;i>=0;i−−)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)−(b)) < EPS)
#define INIT(a) memset(a,0,sizeof(a))

using namespace std;
typedef double D;
typedef pair<D,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const D EPS = 1e-7;
const D INF = 1e9;
const D PI = acos(-1);

//辺の定義。必要に応し&#12441;て削る。
struct edge{
  int from,to,cap,rev;
  edge(int a=0,int b=0,int d=0,int e=0):from(a),to(b),cap(d),rev(e){}
};
int v; //ク&#12441;ラフの頂点数
vector<edge> G[110]; //ク&#12441;ラフの隣接リスト表現

//辺の追加。2つ目の辺の追加はフローアルコ&#12441;リス&#12441;ムの残余ク&#12441;ラフ用。 
void AddEdge(int s,int g,int p){
  G[s].pb(edge(s,g,p,G[g].sz));
  G[g].pb(edge(g,s,0,G[s].sz-1));
}

int level[210]; //まて&#12441;の距離 s
int iter[210]; //と&#12441;こまて&#12441;調へ&#12441;終わったか

void bfs(int s){
  memset(level,-1,sizeof(level));
  level[s] = 0;
  queue<int> q;
  q.push(s);
  while(q.sz){
    int u = q.front(); q.pop();
    rep(i,G[u].sz){
      edge &e = G[u][i];
      if(e.cap > 0 && level[e.to] < 0){
	level[e.to] = level[u] + 1;
	q.push(e.to);
      }
    }
  }
}

int dfs(int u, int t, int f){
  if(u==t)return f;
  for(int &i = iter[u];i<(int)G[u].sz;i++){
    edge &e = G[u][i];
    if(e.cap > 0 && level[u] < level[e.to]){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int dinic(int s, int t){
  int res = 0;
  for(;;){
    bfs(s);
    if(level[t]<0)return res;
    INIT(iter);
    int f;
    while((f=dfs(s,t,INF))>0)res += f;
  }
}

int n,m;
int a[10010],b[10010];

int main(){
  cin >> n >> m;
  v = 2*n + 1;

  rep(i,m){
    cin >> a[i] >> b[i]; a[i]--; b[i]--;
    rep(j,v)G[j].clr;

    rep(j,n)AddEdge(2*j,2*j+1,1);
    rep(j,i){
      AddEdge(2*a[j]+1,2*b[j],1);
      AddEdge(2*b[j]+1,2*a[j],1);
    }
    AddEdge(2*a[i]+1,v-1,1);
    AddEdge(2*b[i]+1,v-1,1);

    int flow = dinic(1,v-1);
    if(flow==2)cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}
accuracy: 0.5531914893617021
time_ms: 50
memory_kb: 1320
final_rank: 20

code_snippet: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

typedef short Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int s, int d, Weight w){
  g[s].push_back(Edge(s,d,w));
  g[d].push_back(Edge(d,s,0));
}

Matrix flow[200];
Matrix capacity[200];
Weight total[200];

#define RESIDUE(r,s,t) (capacity[r][s][t]-flow[r][s][t])
Weight maximumFlow(const Graph &g, int s, int t) {
   if (s == t) return 2;
  int n = g.size();
  // Matrix flow(n, Array(n)), capacity(n, Array(n));
  // REP(u,n) FOR(e,g[u]) capacity[e->src][e->dst] += e->weight;

  while (1) {
    queue<int> Q; Q.push(s);
    vector<int> prev(n, -1); prev[s] = s;
    while (!Q.empty() && prev[t] < 0) { // s から t へ流せる路をBFSで見つける。
      int u = Q.front(); Q.pop();
      FOR(e,g[u]) if (prev[e->dst] < 0 && RESIDUE(t, u, e->dst) > 0) {
        prev[e->dst] = u;
        Q.push(e->dst);
      }
    }
    
    if (prev[t] < 0) return total[t]; // prev[x] == -1 <=> t-side
    Weight inc = 10000;
    for (int j = t; prev[j] != j; j = prev[j]) {
      inc = min(inc, (Weight)RESIDUE(t, prev[j], j));
    }
    for (int j = t; prev[j] != j; j = prev[j])
      flow[t][prev[j]][j] += inc, flow[t][j][prev[j]] -= inc;
    total[t] += inc;
  }
}

int main() {
  int n,m;
  while(cin>>n>>m) {
    REP(i,2*n) {
      flow[i] = Matrix(2*n,Array(2*n));
      capacity[i] = Matrix(2*n,Array(2*n));
      total[i] = 0;
    }
    Graph g(n*2);
    REP(i,n) {
      add_edge(g,2*i,2*i+1,1);
      REP(j,2*n) {
        capacity[j][2*i][2*i+1]++;
      }
    }
    REP(i,m) {
      int a,b;
      cin >> a >> b;
      a--;b--;
      add_edge(g,2*a+1,2*b,1);
      add_edge(g,2*b+1,2*a,1);
      REP(j,2*n) {
        capacity[j][2*a+1][2*b]++;
        capacity[j][2*b+1][2*a]++;
      }
//      cout << a << " "<< maximumFlow(g,1,0) << endl;
      if (maximumFlow(g,1,2*a) >= 2 && maximumFlow(g,1,2*b) >= 2) {
        puts("Yes");
      } else {
        puts("No");
      }
    }

  }
}
accuracy: 1
time_ms: 320
memory_kb: 35896
final_rank: 19

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

struct edge{int t,c,rev;};
typedef vector<edge> ve;
const int INF = 1e8;

int n,m,a,b;
vector<ve> g,tmp;
bool use[210];

void add(int a,int b,int c){
  g[a].push_back((edge){b,c,g[b].size()});
  g[b].push_back((edge){a,0,g[a].size()-1});
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  use[v] = true;
  rep(i,g[v].size()){
    edge &e = g[v][i];
    if(!use[e.t] && e.c>0){
      int d = dfs(e.t,t,min(e.c,f));
      if(d>0){
	e.c -= d;
	g[e.t][e.rev].c += d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t){
  int res = 0;
  while(1){
    memset(use,0,sizeof(use));
    int f = dfs(s,t,INF);
    if(f == 0)return res;
    res += f;
  }
}

int main(){
  cin >> n >> m;
  g.resize(2*n+1);
  rep(i,2*n+1)g[i].clear();

  rep(i,n)add(2*i+1,2*i+2,1);

  rep(i,m){
    cin >> a >> b;
    tmp = g;
    add(2*a,0,1); add(2*b,0,1);

    if(max_flow(2,0)==2)cout << "Yes\n";
    else cout << "No\n";

    g = tmp;
    add(2*a,2*b-1,1); add(2*b,2*a-1,1);
  }
}
accuracy: 1
time_ms: 320
memory_kb: 1864
final_rank: 3

code_snippet: #include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define MAX_V 210
#define INF 2147483647

struct edge{
	int to, cap, rev;
	
	edge(int t, int c, int r)
	: to(t), cap(c), rev(r)
	{}
};

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int f, int t, int c){
	G[f].push_back(edge(t, c, G[t].size()));
	G[t].push_back(edge(f, 0, G[f].size() - 1));
}

int dfs(int v, int t, int f){
	if(v == t){ return f; }
	used[v] = true;

	for(int i = 0; i < G[v].size(); ++i){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			int d = dfs(e.to, t, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t, int lim = INF){
	int flow = 0;
	for(; lim > 0;){
		memset(used, 0, sizeof used);
		int f = dfs(s, t, lim);
		if(f == 0){ break; }
		flow += f;
		lim -= f;
	}

	return flow;
}

int main(){
	int n, m, a, b;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i){
		add_edge(i * 2, i * 2 + 1, 1);
	}
	for(int i = 0; i < m; ++i){
		scanf("%d%d", &a, &b);
		if(max_flow(3, 2 * a + 1, 1) && max_flow(3, 2 * b + 1, 1)){
			puts("Yes");
		}
		else{
			puts("No");
		}
		
		for(int i = 2; i <= 2 * n + 1; ++i){
			int c = i % 2;
			for(int j = 0; j < G[i].size(); ++j){
				G[i][j].cap = j ? c : 1 - c;
			}
		}

		add_edge(2 * a + 1, 2 * b, 1);
		add_edge(2 * b + 1, 2 * a, 1);
	}
}
accuracy: 1
time_ms: 80
memory_kb: 1304
final_rank: 1