ログインしてください。
提出 #10816297
ソースコード 拡げる
#include "bits/stdc++.h"
#include<assert.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MRE assert(0);
const int inf = 1e17;
const int mod =998244353;
typedef pair<int, int> P;
struct edge {
int to, dir;
};
vector<edge>G[100006];
vector<int>cn[100006];
int a[100006], b[100006];
int d[100006], ced[100006];
int par[100006], siz[100006];
void init(int n) {
rep(i, n) {
par[i] = i; siz[i] = 1;
}
}
int find(int x) {
if (x == par[x])return x;
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x); y = find(y);
if (x == y)return;
if (siz[x] > siz[y])swap(x, y);
par[x] = y;
siz[y] += siz[x];
}
void dfs(int now, int label) {
for (auto e : G[now]) {
int nl = (label + 3 + e.dir) % 3;
int nv = e.to;
if (!(d[nv] & (1 << nl))) {
d[nv] += (1 << nl);
dfs(nv, nl);
}
}
return;
}
signed main() {
int n, m; cin >> n >> m;
init(n);
rep(i, m) {
cin >> a[i] >> b[i];
a[i]--; b[i]--;
G[a[i]].push_back({ b[i],1 });
G[b[i]].push_back({ a[i],-1 });
unite(a[i], b[i]);
}
rep(i, m) {
ced[find(a[i])]++;
}
rep(i, n) {
if (!d[i]) {
d[i] = 1;
dfs(i, 0);
}
cn[find(i)].push_back(d[i]);
}
int ans = 0;
rep(i, n) {
vector<int>cnt(8);
for (int e : cn[i]) {
rep(j, 8) {
if ((j&e)==j)cnt[j]++;
}
}
if (!cnt[1] || !cnt[2] || !cnt[4])ans += ced[i];
else ans+= cnt[1] * cnt[2] + cnt[2] * cnt[4] + cnt[4] * cnt[1] -2* cnt[7] * cnt[7];
}
cout << ans << endl;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - Blackout |
| ユーザ | Rho17 |
| 言語 | C++14 (GCC 5.4.1) |
| 得点 | 1700 |
| コード長 | 1557 Byte |
| 結果 | AC |
| 実行時間 | 116 ms |
| メモリ | 29048 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 1700 / 1700 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 0_00.txt, 0_01.txt, 0_02.txt |
| All | 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 0_00.txt | AC | 3 ms | 7552 KiB |
| 0_01.txt | AC | 3 ms | 7552 KiB |
| 0_02.txt | AC | 3 ms | 7552 KiB |
| 1_00.txt | AC | 3 ms | 7552 KiB |
| 1_01.txt | AC | 14 ms | 12288 KiB |
| 1_02.txt | AC | 82 ms | 17408 KiB |
| 1_03.txt | AC | 78 ms | 19704 KiB |
| 1_04.txt | AC | 81 ms | 19704 KiB |
| 1_05.txt | AC | 82 ms | 19704 KiB |
| 1_06.txt | AC | 79 ms | 19704 KiB |
| 1_07.txt | AC | 84 ms | 24312 KiB |
| 1_08.txt | AC | 83 ms | 24312 KiB |
| 1_09.txt | AC | 78 ms | 19704 KiB |
| 1_10.txt | AC | 85 ms | 29048 KiB |
| 1_11.txt | AC | 78 ms | 19704 KiB |
| 1_12.txt | AC | 87 ms | 29048 KiB |
| 1_13.txt | AC | 80 ms | 19704 KiB |
| 1_14.txt | AC | 62 ms | 15600 KiB |
| 1_15.txt | AC | 62 ms | 15600 KiB |
| 1_16.txt | AC | 62 ms | 15600 KiB |
| 1_17.txt | AC | 49 ms | 12416 KiB |
| 1_18.txt | AC | 109 ms | 19836 KiB |
| 1_19.txt | AC | 109 ms | 19708 KiB |
| 1_20.txt | AC | 108 ms | 19576 KiB |
| 1_21.txt | AC | 116 ms | 19708 KiB |
| 1_22.txt | AC | 109 ms | 19580 KiB |
| 1_23.txt | AC | 106 ms | 19708 KiB |
| 1_24.txt | AC | 110 ms | 19576 KiB |
| 1_25.txt | AC | 108 ms | 19708 KiB |
| 1_26.txt | AC | 104 ms | 19708 KiB |
| 1_27.txt | AC | 103 ms | 19572 KiB |
| 1_28.txt | AC | 105 ms | 19708 KiB |
| 1_29.txt | AC | 114 ms | 19708 KiB |
| 1_30.txt | AC | 104 ms | 19448 KiB |
| 1_31.txt | AC | 104 ms | 19576 KiB |
| 1_32.txt | AC | 106 ms | 19704 KiB |
| 1_33.txt | AC | 106 ms | 19832 KiB |
| 1_34.txt | AC | 105 ms | 19836 KiB |
| 1_35.txt | AC | 91 ms | 17920 KiB |
| 1_36.txt | AC | 98 ms | 19068 KiB |
| 1_37.txt | AC | 102 ms | 19836 KiB |
| 1_38.txt | AC | 85 ms | 16896 KiB |
| 1_39.txt | AC | 81 ms | 16384 KiB |
| 1_40.txt | AC | 104 ms | 19708 KiB |
| 1_41.txt | AC | 104 ms | 19832 KiB |
| 1_42.txt | AC | 90 ms | 18176 KiB |
| 1_43.txt | AC | 99 ms | 18048 KiB |
| 1_44.txt | AC | 111 ms | 19960 KiB |
| 1_45.txt | AC | 80 ms | 15872 KiB |
| 1_46.txt | AC | 105 ms | 19960 KiB |
| 1_47.txt | AC | 104 ms | 19836 KiB |
| 1_48.txt | AC | 89 ms | 17664 KiB |
| 1_49.txt | AC | 96 ms | 18944 KiB |