답안 #446833

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446833 2021-07-23T12:15:26 Z Nima_Naderi Traffic (CEOI11_tra) C++14
40 / 100
5000 ms 89744 KB
//In the name of God
//#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 3e5 + 10;
ll n, m, h, w, ts;
ll te[MXN], tw[MXN], dp[MXN], cmp[MXN], comp[MXN];
vector<ll> adj[MXN], adt[MXN], Top, G[MXN], C[MXN];
bool east[MXN], west[MXN], vis[MXN], is[MXN];
vector<pair<ll, ll>> ANS;
inline void add_edge(ll u, ll v){
	adj[u].push_back(v);
	adt[v].push_back(u);
}
void dfs(ll u){
	vis[u] = 1;
	for(auto v : adj[u]){
		if(!vis[v]) dfs(v);
	}
	Top.push_back(u);
}
void sfd(ll u, ll c){
	comp[u] = c, C[c].push_back(u);
	for(auto v : adt[u]){
		if(!comp[v]) sfd(v, c);
	}
}
ll DFS(ll u){
	ll res = te[u];
	vis[u] = 1;
	for(auto v : G[u]){
		if(!vis[v]) res += DFS(v);
	}
	return res;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
	cin >> n >> m >> h >> w;
	for(int i = 1; i <= n; i ++){
		ll x, y; cin >> x >> y;
		east[i] = (x == h), west[i] = (x == 0);
		cmp[i] = -y;
	}
	for(int i = 1; i <= m; i ++){
		ll u, v, f; cin >> u >> v >> f;
		add_edge(u, v);
		if(f > 1) add_edge(v, u);
	}
	for(int i = 1; i <= n; i ++){
		if(!vis[i]) dfs(i);
	}
	reverse(Top.begin(), Top.end());
	for(int j = 1; j <= n; j ++){
		ll i = Top[j - 1];
		if(!comp[i]) sfd(i, ++ ts);
	}
	for(int i = 1; i <= n; i ++){
		te[comp[i]] += east[i];
		tw[comp[i]] += west[i];
	}
	for(int i = 1; i <= ts; i ++){
		for(auto u : C[i]){
			for(auto v : adj[u]){
				if(comp[v] != i && !is[comp[v]]){
					is[comp[v]] = 1;
					G[i].push_back(comp[v]);
				}
			}
		}
		for(auto X : G[i]) is[X] = 0;
	}
	/*
	cout << ts << '\n';
	cout << "comps : \n";
	for(int i = 1; i <= n; i ++){
		cout << comp[i] << ' ';
	} cout << '\n';
	cout << "edges of scc : \n";
	for(int i = 1; i <= ts; i ++){
		cout << "scc " << i << " : \n";
		cout << "te = " << te[i] << '\n';
		for(auto j : G[i]) cout << j << ' ';
		cout << '\n';
	}
	*/
	for(int i = ts; i; -- i){
		//dp[i] = te[i];
		//for(auto j : G[i]) dp[i] += dp[j];
		fill(vis, vis + ts + 1, 0);
		dp[i] = DFS(i);
	}
	for(int i = 1; i <= n; i ++){
		if(west[i]){
			ANS.push_back({cmp[i], dp[comp[i]]});
		}
	}
	sort(ANS.begin(), ANS.end());
	for(auto X : ANS) cout << X.second << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 28492 KB Output is correct
2 Correct 16 ms 28492 KB Output is correct
3 Correct 16 ms 28492 KB Output is correct
4 Correct 16 ms 28504 KB Output is correct
5 Correct 16 ms 28512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 28540 KB Output is correct
2 Correct 16 ms 28492 KB Output is correct
3 Correct 16 ms 28492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 28552 KB Output is correct
2 Correct 17 ms 28620 KB Output is correct
3 Correct 18 ms 28660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 29004 KB Output is correct
2 Correct 57 ms 29660 KB Output is correct
3 Correct 50 ms 29164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 32624 KB Output is correct
2 Correct 4405 ms 38576 KB Output is correct
3 Correct 1765 ms 33612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 35344 KB Output is correct
2 Execution timed out 5086 ms 40068 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 363 ms 42840 KB Output is correct
2 Execution timed out 5095 ms 48300 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 252 ms 44512 KB Output is correct
2 Execution timed out 5093 ms 47204 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 800 ms 55660 KB Output is correct
2 Execution timed out 5101 ms 64012 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2401 ms 73208 KB Output is correct
2 Execution timed out 5041 ms 83308 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1096 ms 87012 KB Output is correct
2 Execution timed out 5013 ms 85020 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3304 ms 65984 KB Output is correct
2 Execution timed out 5081 ms 89744 KB Time limit exceeded
3 Halted 0 ms 0 KB -