Submission #1110474

# Submission time Handle Problem Language Result Execution time Memory
1110474 2024-11-09T14:13:17 Z vjudge1 Traffic (CEOI11_tra) C++17
0 / 100
900 ms 56428 KB
#include "bits/stdc++.h"
#define F first
#define S second
#define ll long long
#define pii pair<int,int>
const int mxN = 1e6 + 5;
const int mod = 1e9 + 7;
using namespace std;
pii a[mxN];
set<pii>s,e;
vector<vector<int>>v,v1;
bool vis[mxN];
int id[mxN];
int l[mxN],r[mxN];
int mx;
int mn;
int sz;
int ans[mxN];
void dfs(int u){
  mx = max(mx,id[u]);
  if(id[u]) mn = min(mn,id[u]);
  vis[u] = 1;
  for(auto x : v[u]){
    if(vis[x]) continue;
    dfs(x);
  }
}
void dfs1(int u){
  vis[u] = 1;
  for(auto x : v1[u]){
    if(vis[x]) continue;
    dfs1(x);
  }
}
signed main(){
  // ios_base::sync_with_stdio(0);
  // cin.tie(0);
  // cout.tie(0);
  int n,m,A,B;
  cin >>n>>m>>A>>B;
  vector<pii>og;
  for(int i = 1;i <= n;i++){
    cin>>a[i].F>>a[i].S;
    if(a[i].F == 0) {
      s.insert({a[i].S,i});
      og.push_back({a[i].S,i});
    }
    if(a[i].F == A) e.insert({a[i].S,i});
  }
  reverse(og.begin(),og.end());
  sz = s.size();
  v.resize(n + 4);
  v1.resize(n + 4);
  for(int i = 1;i <= m;i++){
    int x,y,t;
    cin >>x>>y>>t;
    v[x].push_back(y);
    v1[y].push_back(x);
    if(t == 2) v[y].push_back(x);
    if(t == 2) v1[x].push_back(y);
  }
  queue<pii>rem;
  for(auto x : s){
    dfs(x.S);
  }
  for(auto x : e){
    if(!vis[x.S]) rem.push(x);
  }
  while(rem.size()){
    e.erase(rem.front());
    rem.pop();
  }
  memset(vis,0,sizeof vis);
  for(auto x : e){
    dfs1(x.S);
  }
  for(auto x : s){
    if(!vis[x.S]) rem.push(x);
  }
  while(rem.size()){
    s.erase(rem.front());
    rem.pop();
  }
  memset(vis,0,sizeof vis);
  int ids = 1;
  for(auto x : e) id[x.S] = ids++;
  vector<pii>temp;
  for(auto x : s){
    mx = 0;
    cout<<x.S<<' ';
    dfs(x.S);
    if(mx == 0) mx = e.size();
    r[x.S] = mx;
    temp.push_back(x);
  }
  cout<<'\n';
  memset(vis,0,sizeof vis);
  reverse(temp.begin(),temp.end());
  for(auto x : temp){
    mn = 1e9;
    dfs(x.S);
    if(mn == 1e9) mn = 1;
    l[x.S] = mn;
    ans[x.S] = r[x.S] - l[x.S] + 1;
  }
  for(auto x : og){
    cout<<ans[x.S]<<'\n';
  }

}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 11088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 15332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 21832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 145 ms 23624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 262 ms 32328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 410 ms 44788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 900 ms 56428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 267 ms 39732 KB Output isn't correct
2 Halted 0 ms 0 KB -