제출 #48288

#제출 시각아이디문제언어결과실행 시간메모리
48288choikiwon전압 (JOI14_voltage)C++17
0 / 100
86 ms12732 KiB
#include<bits/stdc++.h> using namespace std; const int MN = 100010; int N, M; vector<int> adj[MN], U, V; int tin[MN], timer, cnt; priority_queue<int> pq1, pq2; int ans; void dfs0(int u, int fe) { tin[u] = timer++; for(int i = 0; i < adj[u].size(); i++) { int e = adj[u][i]; int v = U[e] + V[e] - u; if(e == fe) continue; if(tin[v] == -1) { dfs0(v, e); } else if(tin[v] < tin[u]) { if(tin[v] % 2 == tin[u] % 2) cnt++; } } } void dfs1(int u, int fe) { tin[u] = timer++; for(int i = 0; i < adj[u].size(); i++) { int e = adj[u][i]; int v = U[e] + V[e] - u; if(e == fe) continue; if(tin[v] == -1) { dfs1(v, e); } } for(int i = 0; i < adj[u].size(); i++) { int e = adj[u][i]; int v = U[e] + V[e] - u; if(e == fe) continue; if(tin[v] != -1 && tin[v] < tin[u]) { if(tin[v] % 2 == tin[u] % 2) pq1.push(tin[v]); else pq2.push(tin[v]); } } while(!pq1.empty() && pq1.top() == tin[u]) pq1.pop(); while(!pq2.empty() && pq2.top() == tin[u]) pq2.pop(); if(u && (int)pq1.size() == cnt && !pq2.size()) ans++; } int main() { scanf("%d %d", &N, &M); for(int i = 0; i < M; i++) { int u, v; scanf("%d %d", &u, &v); u--; v--; adj[u].push_back(U.size()); adj[v].push_back(U.size()); U.push_back(u); V.push_back(v); } memset(tin, -1, sizeof(tin)); for(int i = 0; i < N; i++) if(tin[i] == -1) { dfs0(i, -1); } memset(tin, -1, sizeof(tin)); for(int i = 0; i < N; i++) if(tin[i] == -1) { dfs1(i, -1); } if(cnt == 1) ans++; printf("%d", ans); }

컴파일 시 표준 에러 (stderr) 메시지

voltage.cpp: In function 'void dfs0(int, int)':
voltage.cpp:14:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[u].size(); i++) {
                    ~~^~~~~~~~~~~~~~~
voltage.cpp: In function 'void dfs1(int, int)':
voltage.cpp:29:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[u].size(); i++) {
                    ~~^~~~~~~~~~~~~~~
voltage.cpp:37:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[u].size(); i++) {
                    ~~^~~~~~~~~~~~~~~
voltage.cpp: In function 'int main()':
voltage.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~~
voltage.cpp:55:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int u, v; scanf("%d %d", &u, &v);
                   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...