結果

問題 No.1420 国勢調査 (Easy)
ユーザー kkishikkishi
提出日時 2021-03-12 02:28:39
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 9,008 bytes
コンパイル時間 4,709 ms
コンパイル使用メモリ 167,168 KB
実行使用メモリ 43,952 KB
最終ジャッジ日時 2024-10-13 12:58:36
合計ジャッジ時間 29,990 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 7 WA * 13 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
template <typename T>
class Graph {
public:
struct Edge {
int from, to;
T weight;
};
Graph(int n) : edges_(n) {}
void AddEdge(int from, int to, T weight = T()) {
edges_[from].push_back({from, to, weight});
}
const std::vector<Edge> &Edges(int from) const { return edges_[from]; }
int NumVertices() const { return edges_.size(); }
private:
std::vector<std::vector<Edge>> edges_;
};
template <typename T>
std::vector<std::vector<int>> StronglyConnectedComponents(
const Graph<T>& graph) {
int n = graph.NumVertices();
std::vector<int> nodes;
std::vector<bool> visited(n);
std::function<void(int)> dfs = [&](int u) {
visited[u] = true;
for (const auto& e : graph.Edges(u)) {
if (!visited[e.to]) {
dfs(e.to);
}
}
nodes.push_back(u);
};
for (int u = 0; u < n; ++u) {
if (!visited[u]) dfs(u);
}
std::vector<std::vector<int>> rgraph(n);
for (int u = 0; u < n; ++u) {
for (const auto& e : graph.Edges(u)) {
rgraph[e.to].push_back(u);
}
}
std::vector<bool> rvisited(n);
std::vector<std::vector<int>> sccs;
std::function<void(std::vector<int>&, int)> rdfs = [&](std::vector<int>& scc,
int u) {
rvisited[u] = true;
scc.push_back(u);
for (int v : rgraph[u]) {
if (!rvisited[v]) {
rdfs(scc, v);
}
}
};
for (int i = n - 1; i >= 0; --i) {
int u = nodes[i];
if (!rvisited[u]) {
std::vector<int> scc;
rdfs(scc, u);
sccs.push_back(scc);
}
}
return sccs;
}
#include <boost/hana/functional/fix.hpp>
template <typename T, typename = void>
struct is_dereferenceable : std::false_type {};
template <typename T>
struct is_dereferenceable<T, std::void_t<decltype(*std::declval<T>())>>
: std::true_type {};
template <typename T, typename = void>
struct is_iterable : std::false_type {};
template <typename T>
struct is_iterable<T, std::void_t<decltype(std::begin(std::declval<T>())),
decltype(std::end(std::declval<T>()))>>
: std::true_type {};
template <typename T, typename = void>
struct is_applicable : std::false_type {};
template <typename T>
struct is_applicable<T, std::void_t<decltype(std::tuple_size<T>::value)>>
: std::true_type {};
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args);
template <typename T>
void debug(const T& v) {
if constexpr (is_dereferenceable<T>::value) {
std::cerr << "{";
if (v) {
debug(*v);
} else {
std::cerr << "nil";
}
std::cerr << "}";
} else if constexpr (is_iterable<T>::value &&
!std::is_same<T, std::string>::value) {
std::cerr << "{";
for (auto it = std::begin(v); it != std::end(v); ++it) {
if (it != std::begin(v)) std::cerr << ", ";
debug(*it);
}
std::cerr << "}";
} else if constexpr (is_applicable<T>::value) {
std::cerr << "{";
std::apply([](const auto&... args) { debug(args...); }, v);
std::cerr << "}";
} else {
std::cerr << v;
}
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
debug(value);
std::cerr << ", ";
debug(args...);
}
#if DEBUG
#define dbg(...) \
do { \
cerr << #__VA_ARGS__ << ": "; \
debug(__VA_ARGS__); \
cerr << " (L" << __LINE__ << ")\n"; \
} while (0)
#else
#define dbg(...)
#endif
void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
std::cin >> value;
read_from_cin(args...);
}
#define rd(type, ...) \
type __VA_ARGS__; \
read_from_cin(__VA_ARGS__);
#define ints(...) rd(int, __VA_ARGS__);
#define strings(...) rd(string, __VA_ARGS__);
template <typename T>
void write_to_cout(const T& value) {
if constexpr (std::is_same<T, bool>::value) {
std::cout << (value ? "Yes" : "No");
} else if constexpr (is_iterable<T>::value &&
!std::is_same<T, std::string>::value) {
for (auto it = std::begin(value); it != std::end(value); ++it) {
if (it != std::begin(value)) std::cout << " ";
std::cout << *it;
}
} else {
std::cout << value;
}
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
write_to_cout(value);
std::cout << ' ';
write_to_cout(args...);
}
#define wt(...) \
do { \
write_to_cout(__VA_ARGS__); \
cout << '\n'; \
} while (0)
#define all(x) (x).begin(), (x).end()
#define eb(...) emplace_back(__VA_ARGS__)
#define pb(...) push_back(__VA_ARGS__)
#define dispatch(_1, _2, _3, name, ...) name
#define as_i64(x) \
( \
[] { \
static_assert( \
std::is_integral< \
typename std::remove_reference<decltype(x)>::type>::value, \
"rep macro supports std integral types only"); \
}, \
static_cast<std::int64_t>(x))
#define rep3(i, a, b) for (std::int64_t i = as_i64(a); i < as_i64(b); ++i)
#define rep2(i, n) rep3(i, 0, n)
#define rep1(n) rep2(_loop_variable_, n)
#define rep(...) dispatch(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep3(i, a, b) for (std::int64_t i = as_i64(b) - 1; i >= as_i64(a); --i)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep1(n) rrep2(_loop_variable_, n)
#define rrep(...) dispatch(__VA_ARGS__, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define each3(k, v, c) for (auto&& [k, v] : c)
#define each2(e, c) for (auto&& e : c)
#define each(...) dispatch(__VA_ARGS__, each3, each2)(__VA_ARGS__)
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
for (T& vi : v) is >> vi;
return is;
}
template <typename T, typename U>
std::istream& operator>>(std::istream& is, std::pair<T, U>& p) {
is >> p.first >> p.second;
return is;
}
template <typename T, typename U>
bool chmax(T& a, U b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T, typename U>
bool chmin(T& a, U b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T, typename U>
auto max(T a, U b) {
return a > b ? a : b;
}
template <typename T, typename U>
auto min(T a, U b) {
return a < b ? a : b;
}
template <typename T>
std::int64_t sz(const T& v) {
return std::size(v);
}
template <typename T>
std::int64_t popcount(T i) {
return std::bitset<std::numeric_limits<T>::digits>(i).count();
}
template <typename T>
bool hasbit(T s, int i) {
return std::bitset<std::numeric_limits<T>::digits>(s)[i];
}
template <typename T, typename U>
auto div_floor(T n, U d) {
if (d < 0) {
n = -n;
d = -d;
}
if (n < 0) {
return -((-n + d - 1) / d);
}
return n / d;
};
template <typename T, typename U>
auto div_ceil(T n, U d) {
if (d < 0) {
n = -n;
d = -d;
}
if (n < 0) {
return -(-n / d);
}
return (n + d - 1) / d;
}
template <typename T>
bool even(T x) {
return x % 2 == 0;
}
const std::int64_t big = std::numeric_limits<std::int64_t>::max() / 4;
using i64 = std::int64_t;
using i32 = std::int32_t;
template <typename T>
using low_priority_queue =
std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;
void Main();
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout << std::fixed << std::setprecision(20);
Main();
return 0;
}
const auto& Fix = boost::hana::fix;
using namespace std;
#define int i64
void Main() {
ints(n, m);
V<int> a(m), b(m), y(m);
rep(i, m) cin >> a[i] >> b[i] >> y[i];
V<int> ans(n);
rep(i, 30) {
Graph<int> g(n * 2);
rep(j, m) {
int A = a[j] - 1;
int B = b[j] - 1;
int C = hasbit(y[j], i);
if (C == 0) {
// !A v B
g.AddEdge(A, B);
g.AddEdge(n + B, n + A);
// A v !B
g.AddEdge(n + A, n + B);
g.AddEdge(B, A);
} else {
// A v B
g.AddEdge(n + A, B);
g.AddEdge(n + B, A);
// !A v !B
g.AddEdge(A, n + B);
g.AddEdge(B, n + A);
}
}
VV<int32_t> scc = StronglyConnectedComponents(g);
V<int> t(n), f(n);
rep(i, scc.size()) for (int j : scc[i]) {
if (j < n) {
t[j] = i;
} else {
f[j - n] = i;
}
}
V<int> v;
rep(i, n) {
if (t[i] == f[i]) {
wt(-1);
return;
}
if (t[i] > f[i]) ans[i] |= 1 << i;
}
}
each(e, ans) wt(e);
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0