Submission #25755

#TimeUsernameProblemLanguageResultExecution timeMemory
25755dotorya전압 (JOI14_voltage)C++14
100 / 100
276 ms18040 KiB
#include <stdio.h> #include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> #pragma warning(disable:4996) #pragma comment(linker, "/STACK:336777216") using namespace std; #define mp make_pair #define Fi first #define Se second #define pb(x) push_back(x) #define szz(x) ((int)(x).size()) #define rep(i, n) for(int i=0;i<n;i++) #define all(x) (x).begin(), (x).end() #define ldb ldouble typedef tuple<int, int, int> t3; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef pair <ll, int> pli; typedef pair <db, db> pdd; int IT_MAX = 1 << 19; const ll MOD = 1000000007; const int INF = 0x3f3f3f3f; const ll LL_INF = 0x3f3f3f3f3f3f3f3f; const db PI = acos(-1); const db ERR = 1e-10; class edge { public: int s, e; edge() { *this = edge(0, 1); } edge(int s, int e) : s(s), e(e) {} }; vector <edge> Ve; vector <int> conn[100050]; void epush(int a, int b) { conn[a].push_back(Ve.size()); conn[b].push_back(Ve.size()); Ve.emplace_back(a, b); } vector <int> Vv; int par[100050]; int dep[100050]; bool dchk[100050]; int lr[100050][2]; int tus = 0; void DFS(int n) { Vv.push_back(n); dchk[n] = true; lr[n][0] = ++tus; for (auto it : conn[n]) { int n2 = Ve[it].s + Ve[it].e - n; if (dchk[n2]) continue; par[n2] = it; dep[n2] = dep[n] + 1; DFS(n2); } lr[n][1] = tus; } int bit[300000]; void update(int p, int v) { for (; p <= IT_MAX; p += p & (-p)) bit[p] += v; } int getsum(int p) { int rv = 0; for (; p; p -= p & (-p)) rv += bit[p]; return rv; } vector <pii> Va; int main() { int N, M, i, j; scanf("%d %d", &N, &M); for (i = 1; i <= M; i++) { int t1, t2; scanf("%d %d", &t1, &t2); epush(t1, t2); } for (i = 1; i <= N; i++) { if (dchk[i]) continue; par[i] = -1; tus = 0; Vv.clear(); DFS(i); for (IT_MAX = 2; IT_MAX < Vv.size(); IT_MAX *= 2); for (j = 1; j <= IT_MAX; j++) bit[j] = 0; int c1 = 0; for (auto n1 : Vv) { for (auto it : conn[n1]) { int n2 = Ve[it].s + Ve[it].e - n1; if (dep[n1] > dep[n2]) continue; if (par[n2] == it) continue; if (dep[n1] % 2 == dep[n2] % 2) { c1++; update(lr[n2][0], 1); update(lr[n1][0], -1); } else { update(lr[n2][0], -1); update(lr[n1][0], 1); } } } int ans = 0; if (c1 == 1) ans++; for (auto it : Vv) if (it != i && getsum(lr[it][1]) - getsum(lr[it][0] - 1) == c1) ans++; Va.emplace_back(ans, !!c1); } int c = 0; for (auto it : Va) c += it.second; if (c >= 2) return !printf("0\n"); int t = 0; for (auto it : Va) if (it.second == c) t += it.first; return !printf("%d\n", t); }

Compilation message (stderr)

voltage.cpp:23:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable:4996)  
 ^
voltage.cpp:24:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/STACK:336777216")  
 ^
voltage.cpp: In function 'int main()':
voltage.cpp:115:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (IT_MAX = 2; IT_MAX < Vv.size(); IT_MAX *= 2);
                           ^
voltage.cpp:102:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
                        ^
voltage.cpp:105:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &t1, &t2);
                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...