# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
109155 | 2019-05-05T06:02:11 Z | njchung99 | 전압 (JOI14_voltage) | C++14 | 148 ms | 15172 KB |
#include<cstdio> #include<algorithm> #include<vector> #include<cstring> #include<stack> using namespace std; int n, m; stack<int> st; pair<int, int> a[200010]; vector<vector<int>> vt; int par[100010]; int de[100010]; int visited[100010]; int used[100010]; int dp[100010]; int dp1[100010]; int dap = 0; int odd = 0; void dfs(int here) { st.push(here); visited[here] = 1; for (int i = 0; i < vt[here].size(); i++) { int id = vt[here][i]; int next = a[id].first^a[id].second^here; if (!visited[next]) { used[id] = 1; par[next] = here; de[next] = de[here] + 1; dfs(next); } } } int main() { scanf("%d %d", &n, &m); vt.resize(n + 1); for (int i = 0; i < m; i++) { int q, w; scanf("%d %d", &q, &w); vt[q].push_back(i); vt[w].push_back(i); a[i] = { q,w }; } for (int i = 1; i <= n; i++) { if(!visited[i]) dfs(i); } for (int i = 0; i < m; i++) { if (used[i])continue; if (de[a[i].first] < de[a[i].second]) swap(a[i].first, a[i].second); if (de[a[i].first] % 2 == de[a[i].second] % 2) { dp[a[i].first]++; dp[a[i].second]--; odd++; } else { dp1[a[i].first]++; dp1[a[i].second]--; } } if (odd == 1)dap++; while (st.size()) { int t = st.top(); int p = par[t]; st.pop(); if (dp[t] == odd && de[t] && dp1[t] == 0)dap++; dp[p] += dp[t]; dp1[p] += dp1[t]; } printf("%d\n", dap); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 512 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 512 KB | Output is correct |
6 | Correct | 4 ms | 512 KB | Output is correct |
7 | Correct | 4 ms | 512 KB | Output is correct |
8 | Correct | 4 ms | 512 KB | Output is correct |
9 | Correct | 4 ms | 512 KB | Output is correct |
10 | Correct | 4 ms | 512 KB | Output is correct |
11 | Correct | 4 ms | 512 KB | Output is correct |
12 | Correct | 3 ms | 512 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 74 ms | 10068 KB | Output is correct |
2 | Correct | 119 ms | 13232 KB | Output is correct |
3 | Correct | 52 ms | 10096 KB | Output is correct |
4 | Correct | 116 ms | 14172 KB | Output is correct |
5 | Correct | 10 ms | 1612 KB | Output is correct |
6 | Correct | 146 ms | 12024 KB | Output is correct |
7 | Correct | 128 ms | 15096 KB | Output is correct |
8 | Correct | 148 ms | 15128 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 9724 KB | Output is correct |
2 | Correct | 44 ms | 15172 KB | Output is correct |
3 | Incorrect | 52 ms | 15076 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 76 ms | 11584 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |