結果
| 問題 | No.3508 OR Mapping |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 18:45:14 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,376 bytes |
| 記録 | |
| コンパイル時間 | 4,175 ms |
| コンパイル使用メモリ | 357,436 KB |
| 実行使用メモリ | 169,460 KB |
| 最終ジャッジ日時 | 2026-04-18 18:45:48 |
| 合計ジャッジ時間 | 23,271 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 28 WA * 37 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
//高速化
struct ponjuice{ponjuice(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}}PonJuice;
//#define endl '\n' //インタラクティブ問題の時は消す
//型
using ll = long long;
using ld = long double;
template<class T>using vc = vector<T>; template<class T>using vvc = vc<vc<T>>; template<class T>using vvvc = vvc<vc<T>>;
using vi = vc<int>; using vvi = vvc<int>; using vvvi = vvvc<int>;
using vl = vc<ll>; using vvl = vvc<ll>; using vvvl = vvvc<ll>;
using pi = pair<int, int>; using pl = pair<ll, ll>;
using ull = unsigned ll;
template<class T>using priq = priority_queue<T>;
template<class T>using priqg = priority_queue<T, vc<T>, greater<T>>;
// for文
#define overload4(a, b, c, d, e, ...) e
#define rep1(n) for(ll i = 0; i < n; i++)
#define rep2(i, n) for(ll i = 0; i < n; i++)
#define rep3(i, a, b) for(ll i = a; i < b; i++)
#define rep4(i, a, b, step) for(ll i = a; i < b; i+= step)
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define per1(n) for(ll i = n-1; i >= 0; i--)
#define per2(i, n) for(ll i = n-1; i >= 0; i--)
#define per3(i, a, b) for(ll i = b-1; i >= a; i--)
#define per4(i, a, b, step) for(ll i = b-1; i >= a; i-= step)
#define per(...) overload4(__VA_ARGS__, per4, per3, per2, per1)(__VA_ARGS__)
//関数
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define si(x) (ll)(x).size()
template<class S, class T>inline bool chmax(S& a, T b){return a < b && ( a = b , true);}
template<class S, class T>inline bool chmin(S& a, T b){return a > b && ( a = b , true);}
inline void yes(){cout << "Yes\n";}
inline void no(){cout << "No\n";}
inline void yesno(bool y = true){if(y)yes();else no();}
//定数
constexpr ll mod = 998244353;
constexpr ll minf=-(1<<29);
constexpr ll inf=(1<<29);
constexpr ll MINF=-(1LL<<60);
constexpr ll INF=(1LL<<60);
const int dx[4] ={-1, 0, 1, 0};
const int dy[4] ={ 0, 1, 0,-1};
const int dx8[8] ={-1,-1,-1, 0, 1, 1, 1, 0};
const int dy8[8] ={-1, 0, 1, 1, 1, 0,-1,-1};
void solve();
int main() {
int t = 1;
// cin >>t;
while(t--){
solve();
}
}
/*
せっかくなので、PPC は全てコメント書きます
OR なので、かなり楽そう?
とりあえず,SCCをしてグラフを見る
一つ前のやつから自分に来れないのであれば確実に不可能
強連結成分が2部グラフ(無向グラフとしてみた時) のとき、mod2が01が確定してしまうので、これはNG
連結成分が一つのものがある時、それが連続するとNG
ぐらいかなぁ
k使ってないのちょっと不安だけど
とりあえず書いてみて出すか
なんかREでてる
*/
#include<atcoder/scc>
using namespace atcoder;
void solve(){
int n,m,k;
cin >> n >> m >> k;
scc_graph g(n);
vector<vector<int>> graph(n);
rep(i,0,m) {
int u,v;
cin >> u >> v;
u--,v--;
graph[u].push_back(v);
g.add_edge(u,v);
}
auto res = g.scc();
vector<int> num(n);
rep(i,0,res.size()) {
for(auto c: res[i]) {
num[c] = i;
}
if(i!=0 && res[i-1].size() == 1 && res[i].size() == 1) {
no();
return;
}
}
vector<int> none(res.size()-1, 1);
rep(i,0,n){
for(auto to: graph[i]) {
if(num[i] +1 == num[to]) {
none[num[i]] = 0;
}
}
}
if(accumulate(all(none), 0)) {
no();
return;
}
vector<int> od(n,-1);
auto check = [&,graph](const vector<int>& v) -> bool {
set<int> in(all(v));
bool ok = false;
auto dfs = [&](auto&& self, int nw) -> void {
for(auto to: graph[nw]) {
if(in.count(to) == 0) continue;
if(od[to] == -1) {
od[to] = od[nw]^1;
self(self, to);
}else {
if(od[to] == od[nw]) ok = true;
}
}
};
od[v[0]] = 0;
dfs(dfs, v[0]);
return ok;
};
rep(i,0,res.size()) {
if(res[i].size() != 1) {
if(!check(res[i])) {
no();
return;
}
}
}
return;
}