結果
| 問題 |
No.1293 2種類の道路
|
| コンテスト | |
| ユーザー |
👑 null
|
| 提出日時 | 2020-11-20 22:54:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 70 ms / 2,000 ms |
| コード長 | 6,277 bytes |
| コンパイル時間 | 2,021 ms |
| コンパイル使用メモリ | 149,860 KB |
| 最終ジャッジ日時 | 2025-01-16 02:58:57 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
コンパイルメッセージ
main.cpp: In function ‘void scans(std::string&)’:
main.cpp:80:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
80 | scanf("%c", &c);
| ~~~~~^~~~~~~~~~
main.cpp:81:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
81 | if (c == '\n')scanf("%c", &c);
| ~~~~~^~~~~~~~~~
main.cpp:84:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
84 | scanf("%c", &c);
| ~~~~~^~~~~~~~~~
main.cpp: In function ‘void scanc(char&)’:
main.cpp:90:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
90 | scanf("%c", &c);
| ~~~~~^~~~~~~~~~
main.cpp:93:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
93 | scanf("%c", &c);
| ~~~~~^~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:258:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
258 | scanf("%d%d%d", &n, &d, &w);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:264:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
264 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:270:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
270 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~
ソースコード
/*
このコード、と~おれ!
Be accepted!
∧_∧
(。・ω・。)つ━☆・*。
⊂ ノ ・゜+.
しーJ °。+ *´¨)
.· ´¸.·*´¨) ¸.·*¨)
(¸.·´ (¸.·'* ☆
*/
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
#include <array>
////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//
//#pragma GCC target ("avx2")
//#pragma GCC target("arch=skylake-avx512")
//#pragma GCC optimiz ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()
using ll = long long;
using ull = unsigned long long;
constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);
using namespace std;
void scans(string& str) {
char c;
str = "";
scanf("%c", &c);
if (c == '\n')scanf("%c", &c);
while (c != '\n' && c != -1 && c != ' ') {
str += c;
scanf("%c", &c);
}
}
void scanc(char& str) {
char c;
scanf("%c", &c);
if (c == -1)return;
while (c == '\n') {
scanf("%c", &c);
}
str = c;
}
double acot(double x) {
return PI / 2 - atan(x);
}
ll LSB(ll n) { return (n & (-n)); }
template<typename T>
inline T chmin(T& a, const T& b) {
if (a > b)a = b;
return a;
}
template<typename T>
inline T chmax(T& a, const T& b) {
if (a < b)a = b;
return a;
}
//atcoder library
//#include <atcoder/all>
//using namespace atcoder;
/*-----------------------------------------ここからコード-----------------------------------------*/
using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;
#include <cassert>
#include <cstddef>
#include <numeric>
#include <utility>
#include <vector>
class union_enumerate {
std::vector<usize> next;
public:
union_enumerate() = default;
union_enumerate(const usize size) : next(size) {
std::iota(next.begin(), next.end(), static_cast<usize>(0));
}
usize size() const { return next.size(); }
std::vector<usize> enumerate(const usize x) const {
assert(x < size());
std::vector<usize> ret;
usize y = x;
do {
ret.push_back(y);
y = next[y];
} while (y != x);
return ret;
}
std::vector<std::vector<usize>> get_all() const {
const usize n = size();
std::vector<std::vector<usize>> res;
std::vector<bool> visited(n, false);
for (usize i = 0; i != n; i += 1) {
if (!visited[i]) {
const std::vector<usize> list = enumerate(i);
for (const usize j : list)
visited[j] = true;
res.push_back(list);
}
}
return res;
}
void unite(const usize x, const usize y) {
assert(x < size());
assert(y < size());
std::swap(next[x], next[y]);
}
};
/*
* @title unionfind
* @docs kyopro/docs/unionfind.md
*/
//0-indexed
struct unionfind {
vector<int> par, siz;
unionfind(int n) : par(n), siz(n) {
for (int i = 0; i < n; ++i) {
//全部根で初期化
par[i] = i;
//サイズは1
siz[i] = 1;
}
}
void init(int n) {
par.resize(n);
siz.resize(n);
for (int i = 0; i < n; ++i) {
//全部根で初期化
par[i] = i;
//サイズは1
siz[i] = 1;
}
}
//根を返す
int find(int a) {
return par[a] == a ? a : par[a] = find(par[a]);
}
//くっつける。元から同じだったらfalseを返す
bool unite(int a, int b) {
int x = find(a), y = find(b);
if (x == y)return false;
else if (siz[x] < siz[y]) {
par[x] = y;
siz[y] += siz[x];
}
else if (siz[x] > siz[y]) {
par[y] = x;
siz[x] += siz[y];
}
else {
par[x] = y;
siz[y] += siz[x];
}
return true;
}
//同じ集合か判定する
bool same(int a, int b) {
return find(a) == find(b);
}
//サイズを返す
int size(int a) {
return siz[find(a)];
}
//同じ集合に属す葉を纏めて返す
vector<int> leaf(int a) {
vector<int> x;
int n = par.size();
for (int i = 0; i < n; ++i)if (same(a, i))x.push_back(i);
return x;
}
};
int main() {
int n, d, w;
scanf("%d%d%d", &n, &d, &w);
union_enumerate car(n), walk(n);
unionfind cntc(n), cntw(n);
ll ans = 0;
rep(i, d) {
int a, b;
scanf("%d%d", &a, &b);
if(not cntc.same(a - 1, b - 1)) car.unite(a - 1, b - 1);
cntc.unite(a - 1, b - 1);
}
rep(i, w) {
int a, b;
scanf("%d%d", &a, &b);
if (not cntw.same(a - 1, b - 1)) walk.unite(a - 1, b - 1);
cntw.unite(a - 1, b - 1);
}
vector<bool> flag(n);
rep(i, n) {
if (not flag[i]) {
auto ushi = car.enumerate(i);
ll m = 0, x = cntc.size(i);
set<int> b;
for (const auto& aa : ushi)b.insert(cntw.find(aa)), flag[aa] = true;
for (const auto& aa : b)m += cntw.size(aa);
ans += m * x;
flag[i] = true;
}
}
printf("%lld\n", ans - (ll)n);
Please AC;
}
null