Submission #728100

# Submission time Handle Problem Language Result Execution time Memory
728100 2023-04-22T02:09:41 Z PenguinsAreCute Pipes (CEOI15_pipes) C++17
30 / 100
1713 ms 65536 KB
#include <iostream>
#include <vector>
using namespace std;
#define speed ios_base::sync_with_stdio(false); cin.tie(0)
typedef vector<int> vi;
#define pb push_back
#define REP(i, a, b) for(int i = a; i < b; i++)
#define MAXN 100005
vi adj[MAXN], adj_dfs3[MAXN];
int h[MAXN], bEdgeD[MAXN], bEdgeU[MAXN], crossEdges[MAXN], par[MAXN];
bool visited[MAXN];
void dfs(int x) {
    visited[x] = true;
    for(auto i: adj[x]) if(!visited[i]) {
		par[i]=x;
    	adj_dfs3[x].pb(i);
        adj_dfs3[i].pb(x);
        h[i]=h[x]+1;
        dfs(i);
	}
}
int dp(int x) {
    if(~crossEdges[x]) return crossEdges[x];
    crossEdges[x]=bEdgeU[x]-bEdgeD[x];
    for(auto i:adj_dfs3[x]) if(h[i]>h[x]) crossEdges[x]+=dp(i);
    return crossEdges[x];
}
int32_t main() {
	speed;
    int N, E, A, B, ans; cin >> N >> E;
    REP(i,0,E) {
        cin>>A>>B;
        adj[A].pb(B);
        adj[B].pb(A);
    }
    REP(i,1,N+1)if(!visited[i]) dfs(i);
	REP(i,1,N+1) for(auto j: adj[i]) {
        if(h[i]>h[j]) bEdgeU[i]++;
        else bEdgeD[i]++;
    }
	REP(i,1,N+1) crossEdges[i]=-1;
	REP(i,1,N+1) if(par[i] && dp(i)==1) cout << i << " " << par[i] << "\n";
}

Compilation message

pipes.cpp: In function 'int32_t main()':
pipes.cpp:30:21: warning: unused variable 'ans' [-Wunused-variable]
   30 |     int N, E, A, B, ans; cin >> N >> E;
      |                     ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5844 KB Output is correct
2 Correct 7 ms 5552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 13340 KB Output is correct
2 Correct 103 ms 12728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 206 ms 16880 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 435 ms 28024 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 651 ms 34640 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1153 ms 56552 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1280 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1531 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1713 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -