結果

問題 No.1023 Cyclic Tour
ユーザー momoharamomohara
提出日時 2020-04-10 22:14:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,069 bytes
コンパイル時間 2,335 ms
コンパイル使用メモリ 180,224 KB
実行使用メモリ 36,460 KB
最終ジャッジ日時 2023-10-14 00:53:56
合計ジャッジ時間 12,408 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 127 ms
28,656 KB
testcase_05 AC 133 ms
28,584 KB
testcase_06 AC 145 ms
31,292 KB
testcase_07 AC 132 ms
29,712 KB
testcase_08 AC 98 ms
25,284 KB
testcase_09 AC 92 ms
24,728 KB
testcase_10 AC 98 ms
24,480 KB
testcase_11 AC 102 ms
25,904 KB
testcase_12 AC 92 ms
24,672 KB
testcase_13 AC 85 ms
23,228 KB
testcase_14 AC 82 ms
23,200 KB
testcase_15 AC 94 ms
23,764 KB
testcase_16 AC 167 ms
31,952 KB
testcase_17 AC 160 ms
32,832 KB
testcase_18 AC 162 ms
31,936 KB
testcase_19 AC 151 ms
31,272 KB
testcase_20 AC 183 ms
35,756 KB
testcase_21 AC 196 ms
36,372 KB
testcase_22 AC 176 ms
34,532 KB
testcase_23 AC 167 ms
35,212 KB
testcase_24 AC 156 ms
33,948 KB
testcase_25 AC 182 ms
35,848 KB
testcase_26 AC 172 ms
35,868 KB
testcase_27 AC 157 ms
34,956 KB
testcase_28 AC 148 ms
33,116 KB
testcase_29 AC 143 ms
31,404 KB
testcase_30 AC 162 ms
35,204 KB
testcase_31 AC 158 ms
35,256 KB
testcase_32 AC 163 ms
33,432 KB
testcase_33 AC 176 ms
35,804 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 197 ms
35,432 KB
testcase_37 AC 182 ms
34,864 KB
testcase_38 AC 158 ms
32,344 KB
testcase_39 AC 175 ms
33,712 KB
testcase_40 AC 175 ms
35,168 KB
testcase_41 AC 180 ms
34,772 KB
testcase_42 AC 197 ms
36,184 KB
testcase_43 AC 147 ms
31,368 KB
testcase_44 AC 125 ms
29,136 KB
testcase_45 AC 106 ms
30,956 KB
testcase_46 AC 124 ms
31,056 KB
testcase_47 AC 136 ms
29,224 KB
testcase_48 AC 138 ms
34,760 KB
testcase_49 AC 147 ms
35,472 KB
testcase_50 AC 146 ms
35,340 KB
testcase_51 AC 139 ms
34,544 KB
testcase_52 AC 149 ms
34,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;

typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

//constexpr long long MOD = (ll) 1e9+7;
constexpr long long MOD = 998244353;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

struct Edge {
	int to, cap, rev;
	Edge(int _to, int _cap, int _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, int from, int to, int cap, bool revFlag, int revCap) {
	G[from].push_back(Edge(to, cap, G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}


//強連結成分分解
class SCC{
	Graph g,rg;
	vector<int> cmp,used,vs;
	int size;
public:
	SCC(Graph _g):g(_g),rg(g.size()),cmp(g.size(),-1),used(g.size(),false){
		REP(i,g.size()){
			for(auto e:g[i]){
				add_edge(rg,e.to,i,1,false,0);//逆辺のグラフ
			}
		}

		REP(i,g.size()){
			if(!used[i]) dfs(i);
		}
		int k=0;
		
		REP(i,vs.size()){
			ll v=vs[vs.size()-1-i];
			if(used[v]){
				rdfs(v,k);
				k++;
			}
		}
		size=k;
	}

	void dfs(int v){
		//帰りがけ順に番号を振る
		used[v]=true;
		for(auto e:g[v]){
			if(!used[e.to]) dfs(e.to);
		}
		vs.push_back(v);
	}

	void rdfs(int v, int k){
		//通ることができた頂点に番号を振る
		used[v]=false;
		cmp[v]=k;
		for(auto e:rg[v]){
			if(used[e.to]) rdfs(e.to,k);
		}
	}

	int getSize(){
		return size;
	}

	int group(int v){
		return cmp[v];
	}

  Graph rebuild(){
		//縮約したグラフを返す
		Graph ret(size);
		REP(i,g.size()){
			int u=cmp[i];
			for(auto e:g[i]){
				int v=cmp[e.to];
				if(u==v) continue;
				cout<<u<<" "<<v<<e.cap<<en;
				add_edge(ret,u,v,e.cap,false,0);
			}
		}
		return ret;
	}
};

void solve() {
    ll n,m;
    cin>>n>>m;
    Graph g(n);
    vec<P> ab;
    REP(i,m){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        if(c==1){ 
            add_edge(g,a,b,1,true,1);

        }else{ 
            add_edge(g,a,b,1,false,1);
            ab.push_back({a,b});
        }
        
    }
    SCC scc(g);
    REP(i,ab.size()){
        if(scc.group(ab[i].first)==scc.group(ab[i].second)){
            cout<<"Yes"<<en;
            return;
        }
    }
    cout<<"No"<<en;

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}
0