結果
| 問題 |
No.1023 Cyclic Tour
|
| コンテスト | |
| ユーザー |
micheeeeell1001
|
| 提出日時 | 2020-04-10 21:57:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,476 bytes |
| コンパイル時間 | 3,230 ms |
| コンパイル使用メモリ | 223,892 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-09-15 20:17:11 |
| 合計ジャッジ時間 | 7,771 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | TLE * 1 -- * 48 |
ソースコード
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll
//頂点fromから頂点toへのコストcostの辺
template<typename T>
struct edge{
int f,t;
T c;
int id;
edge(){};
edge(int f,int t,T c,int id = 0):f(f),t(t),c(c),id(id){};
bool operator< (const edge &s){
return c < s.c;
}
};
template<typename T>
struct graph{
std::vector<std::vector<edge<T> > > data;
graph(int v):data(v){};
void add_edge(edge<T> &e){
data[e.f].push_back(e);
}
void add_edge(int f,int t,T c){
data[f].emplace_back(f,t,c);
}
size_t size(){
return data.size();
}
std::vector<edge<T>> make_edges(){
std::vector<edge<T>> r;
for(auto &i:data)std::copy(i.begin(),i.end(),std::back_inserter(r));
return r;
}
};
vector<int> is_moved(n_max,0);
template<typename T>
void reach(graph<T> &g, int pos){
is_moved[pos] = 1;
for(auto i : g.data[pos]){
if(!is_moved[i.t]){
reach(g, i.t);
}
}
}
template<typename T>
std::vector<T> bellmanford(graph<T> &g, int s){
const T INF = std::numeric_limits<T>::max()/4;
std::vector<T> data(g.size(),INF);
data[s] = 0;
for(int i=0;i<g.size()-1;i++){
for(auto &v:g.data)for(auto &e:v){
if(data[e.f]==INF)continue;
data[e.t] = std::min(data[e.f] + e.c,data[e.t]);
}
}
for(auto &v:g.data)for(auto &e:v){
if(data[e.f]==INF)continue;
if(data[e.f] + e.c < data[e.t]){
// fill(data.begin(),data.end(),std::numeric_limits<T>::min());
fill(is_moved.begin(),is_moved.end(),0);
reach(g,e.f);
for(T i = 0; i < g.data.size();i++){
if(is_moved[i])data[i] = -INF;
}
break;
}
}
return data;
};
void print() {
cout << endl;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
cout << head;
if (sizeof...(tail) != 0) cout << ' ';
print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
for (auto& a : vec) {
cout << a;
if (&a != &vec.back()) cout << ' ';
}
cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
for (auto& vec : df) {
print(vec);
}
}
template<class T, class U>
void print(pair<T,U> &p){
print(p.first, p.second);
}
signed main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n,m; cin >> n >> m;
graph<ll> g(n);
rep(i,m) {
ll a,b,c; cin >> a >> b >> c;
a--;b--;
if(c == 1){
g.add_edge(a, b, -1);
g.add_edge(b, a, 1);
}
else{
g.add_edge(a, b, -1);
}
}
auto vec = bellmanford(g, 0);
// print(vec);
cout << (*min_element(all(vec)) == -INF ? "Yes" : "No") << endl;
}
micheeeeell1001