Submission #1069891
Source Code Expand
#ifdef DEBUG #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; mt19937 mrand(random_device{} ()); int rnd(int x) { return mrand() % x; } typedef long double ld; typedef long long ll; #ifdef DEBUG #define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #else #define eprintf(...) ; #endif #define pb push_back #define mp make_pair #define sz(x) ((int) (x).size()) #define TASK "text" const int inf = (int) 1.01e9; const ld eps = 1e-9; const ld pi = acos((ld) -1.0); const int mod = (int) 1e9 + 7; void add(int &x, int y) { if ((x += y) >= mod) { x -= mod; } } int mult(int x, int y) { return (long long) x * y % mod; } int myPower(int x, int pw) { int res = 1; for (; pw; pw >>= 1) { if (pw & 1) { res = mult(res, x); } x = mult(x, x); } return res; } void precalc() { } const int maxn = (int) 1e5 + 10; int n, m; vector<vector<int> > es, esrev; int read() { if (scanf("%d%d", &n, &m) < 2) { return 0; } es = esrev = vector<vector<int> >(n); for (int i = 0; i < m; ++i) { int s, t; scanf("%d%d", &s, &t); --s, --t; es[s].pb(t); esrev[t].pb(s); } return 1; } int rem[maxn]; long long cnt[3]; bool fail; int cnte; void dfs(int v) { cnt[rem[v]] += 1; cnte += sz(es[v]); for (int u : es[v]) { int nrem = (rem[v] + 1) % 3; if (rem[u] != -1) { if (rem[u] != nrem) { fail = 1; } continue; } rem[u] = nrem; dfs(u); } for (int u : esrev[v]) { int nrem = (rem[v] + 2) % 3; if (rem[u] != -1) { if (rem[u] != nrem) { fail = 1; } continue; } rem[u] = nrem; dfs(u); } } void solve() { for (int i = 0; i < n; ++i) { rem[i] = -1; } long long res = 0; for (int i = 0; i < n; ++i) { if (rem[i] != -1) { continue; } memset(cnt, 0, sizeof(cnt)); fail = 0; rem[i] = 0; cnte = 0; dfs(i); if (fail) { long long sum = cnt[0] + cnt[1] + cnt[2]; res += sum * sum; } else { if (cnt[0] && cnt[1] && cnt[2]) { res += cnt[0] * cnt[1] + cnt[1] * cnt[2] + cnt[2] * cnt[0]; } else { res += cnte; } } } printf("%lld\n", res); } int main() { precalc(); #ifdef LOCAL freopen(TASK ".out", "w", stdout); assert(freopen(TASK ".in", "r", stdin)); #endif while (1) { if (!read()) { break; } solve(); #ifdef DEBUG eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC); #endif } return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Blackout |
User | XraY |
Language | C++14 (GCC 5.4.1) |
Score | 1700 |
Code Size | 2695 Byte |
Status | AC |
Exec Time | 55 ms |
Memory | 16256 KB |
Compile Error
./Main.cpp: In function ‘int read()’: ./Main.cpp:72:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &s, &t); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1700 / 1700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 3 ms | 256 KB |
0_01.txt | AC | 3 ms | 256 KB |
0_02.txt | AC | 3 ms | 256 KB |
1_00.txt | AC | 3 ms | 256 KB |
1_01.txt | AC | 10 ms | 5376 KB |
1_02.txt | AC | 42 ms | 11520 KB |
1_03.txt | AC | 48 ms | 16256 KB |
1_04.txt | AC | 48 ms | 16256 KB |
1_05.txt | AC | 48 ms | 16256 KB |
1_06.txt | AC | 48 ms | 16256 KB |
1_07.txt | AC | 49 ms | 16256 KB |
1_08.txt | AC | 48 ms | 16256 KB |
1_09.txt | AC | 48 ms | 16256 KB |
1_10.txt | AC | 48 ms | 16256 KB |
1_11.txt | AC | 48 ms | 16256 KB |
1_12.txt | AC | 48 ms | 16256 KB |
1_13.txt | AC | 46 ms | 13184 KB |
1_14.txt | AC | 33 ms | 8824 KB |
1_15.txt | AC | 34 ms | 8824 KB |
1_16.txt | AC | 33 ms | 8824 KB |
1_17.txt | AC | 20 ms | 1536 KB |
1_18.txt | AC | 53 ms | 10368 KB |
1_19.txt | AC | 52 ms | 10368 KB |
1_20.txt | AC | 52 ms | 10368 KB |
1_21.txt | AC | 52 ms | 10496 KB |
1_22.txt | AC | 53 ms | 10496 KB |
1_23.txt | AC | 52 ms | 10496 KB |
1_24.txt | AC | 52 ms | 10368 KB |
1_25.txt | AC | 55 ms | 10496 KB |
1_26.txt | AC | 52 ms | 10368 KB |
1_27.txt | AC | 52 ms | 10368 KB |
1_28.txt | AC | 52 ms | 10368 KB |
1_29.txt | AC | 53 ms | 10496 KB |
1_30.txt | AC | 51 ms | 10240 KB |
1_31.txt | AC | 52 ms | 10368 KB |
1_32.txt | AC | 52 ms | 10368 KB |
1_33.txt | AC | 53 ms | 10496 KB |
1_34.txt | AC | 50 ms | 8832 KB |
1_35.txt | AC | 44 ms | 6144 KB |
1_36.txt | AC | 48 ms | 7808 KB |
1_37.txt | AC | 51 ms | 9856 KB |
1_38.txt | AC | 42 ms | 5248 KB |
1_39.txt | AC | 40 ms | 4736 KB |
1_40.txt | AC | 52 ms | 10112 KB |
1_41.txt | AC | 52 ms | 9984 KB |
1_42.txt | AC | 45 ms | 7040 KB |
1_43.txt | AC | 45 ms | 6400 KB |
1_44.txt | AC | 50 ms | 9088 KB |
1_45.txt | AC | 39 ms | 4096 KB |
1_46.txt | AC | 51 ms | 9472 KB |
1_47.txt | AC | 51 ms | 9984 KB |
1_48.txt | AC | 43 ms | 5760 KB |
1_49.txt | AC | 47 ms | 7552 KB |