Submission #1011866

# Submission time Handle Problem Language Result Execution time Memory
1011866 2024-07-01T10:02:34 Z PenguinsAreCute Pipes (CEOI15_pipes) C++17
20 / 100
1086 ms 65536 KB
#include <vector>
#include <cstdio>
#include <bitset>
using namespace std;
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], crossEdges[MAXN], par[MAXN];
bitset<MAXN> visited;
void dfs(int x) {
	visited[x] = true;
	for(auto i: adj[x]) if(!visited[i]) {
		par[i]=x;
		adj_dfs3[x].pb(i);
		h[i]=h[x]+1;
		dfs(i);
	}
}
int dp(int x) {
	if(visited[x]) return crossEdges[x];
	visited[x] = 1;
	//crossEdges[x]=bEdgeU[x]-bEdgeD[x];
	for(auto i:adj_dfs3[x]) if(h[i]>h[x]) crossEdges[x]+=dp(i);
	return crossEdges[x];
}
int main() {
	int N, E, A, B, ans; scanf("%d %d",&N,&E);
	REP(i,0,E) {
		scanf("%d %d",&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) visited[i]=0;
	REP(i,1,N+1) for(auto j: adj[i]) {
		if(h[i]>h[j]) crossEdges[i]++;
		else crossEdges[i]--;
	}
	REP(i,1,N+1) if(par[i]&&dp(i)==1) printf("%d %d\n",i,par[i]);
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:29:18: warning: unused variable 'ans' [-Wunused-variable]
   29 |  int N, E, A, B, ans; scanf("%d %d",&N,&E);
      |                  ^~~
pipes.cpp:29:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  int N, E, A, B, ans; scanf("%d %d",&N,&E);
      |                       ~~~~~^~~~~~~~~~~~~~~
pipes.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   scanf("%d %d",&A,&B);
      |   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5820 KB Output is correct
2 Correct 5 ms 5464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 98 ms 18776 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 167 ms 26072 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 300 ms 43680 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 425 ms 53608 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 670 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 853 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1042 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1086 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -