結果
| 問題 |
No.1023 Cyclic Tour
|
| コンテスト | |
| ユーザー |
catupper
|
| 提出日時 | 2020-04-10 22:57:15 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,913 bytes |
| コンパイル時間 | 801 ms |
| コンパイル使用メモリ | 76,148 KB |
| 実行使用メモリ | 24,192 KB |
| 最終ジャッジ日時 | 2024-09-15 23:22:56 |
| 合計ジャッジ時間 | 13,949 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 16 WA * 33 |
ソースコード
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
int n, m;
vector<int> edge[110000];
vector<int> rev[110000];
vector<int> group[110000];
int a, b, c;
bool done[110000];
Int comp[110000];
vector<int> nodes;
void dfs(int x, int last = -1){
if(done[x])return;
done[x] = true;
for(auto to:edge[x]){
if(to == last)continue;
dfs(to, x);
}
nodes.push_back(x);
}
void dfs2(int x, int g, int last = -1){
if(done[x])return;
done[x] = true;
group[g].push_back(x);
comp[x] = g;
for(auto to:rev[x]){
if(to == last)continue;
dfs2(to, g, x);
}
}
void scc(){
for(int i = 1;i <= n;i++){
dfs(i);
}
reverse(nodes.begin(), nodes.end());
for(auto node:nodes){
if(!done[node])
dfs2(node, node);
}
}
void ok(){
cout << "Yes" << endl;
exit(0);
}
void ng(){
cout << "No" << endl;
exit(0);
}
bool check(int g){
int V = group[g].size();
if(V == 0)return false;
int E = 0;
cout << "Group " << g << endl;
for(auto v:group[g]){
cout << v << " ";
for(auto to:edge[v]){
if(comp[to] == g)E++;
}
}cout << endl;
if(E == V+1)return false;
return true;
}
int main(){
cin >> n >> m;
for(int i = 0;i < m;i++){
cin >> a >> b >> c;
edge[a].push_back(b);
rev[b].push_back(a);
if(c==2){
edge[b].push_back(a);
rev[a].push_back(b);
}
}
scc();
for(int i = 1;i <= n;i++){
if(check(i))ok();
}
ng();
return 0;
}
catupper