답안 #1111670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111670 2024-11-12T14:27:38 Z vjudge1 Traffic (CEOI11_tra) C++17
0 / 100
533 ms 48608 KB
#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define pb push_back
#define INF 100000000000000000
#define fi first
#define se second
//#define cin fin
//#define cout fout
using namespace std;
double const EPS = 1e-14;
typedef long long ll;
const ll P = 10007;
const ll mod = 1e9 + 7;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
//ofstream fout("cardgame.out");
//ifstream fin("cardgame.in");
const int M = 3e5 + 5;
bool ok[M];
vector<pair<int,int>> a, b;
vector<int> v[M], v2[M];
vector<pair<int,pair<int,int>>> order;
pair<int,int> ans[M];

void check() {
    queue<int> q;
    for(int i = 0; i < a.size(); i++) {
        ok[a[i].se] = 1; q.push(a[i].se);
    }
    while(!q.empty()) {
        int tp = q.front();
        q.pop();
        for(auto i : v[tp]) {
            if(ok[i] == 0){
                ok[i] = 1;
                q.push(i);
            }
        }
    }
}
void dfs(int s, int val) {
    ok[s] = 1;
    for(auto i : v2[s]) {
        if(ok[i] == 0) {
            if(ans[i].fi == -1) ans[i].fi = val;
            else ans[i].se = val;
            dfs(i,val);
        }
    }

}
int main()
{
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    int n, m, A, B; cin >> n >> m >> A >> B;
    for(int i = 0; i < n; i++) {
        int x, y; cin >> x >> y;
        if(x == 0) {
            a.push_back({y,i+1});
        }
        else if(x == A) {
            b.push_back({y,i+1});
        }
    }
    for(int i = 1; i <= n; i++) {
        ans[i].fi = -1; ans[i].se = -1;
    }
    for(int i = 0; i < m; i++) {
        int x, y, tp;
        cin >> x >> y >> tp;
        v2[y].push_back(x);
        v[x].push_back(y);
        if(tp == 2) {
            v[y].push_back(x);
            v2[x].push_back(y);
        }
    }
    check();
    sort(b.begin(),b.end());
    for(int i = 0; i < b.size(); i++) {
        if(ok[b[i].se] == 1) order.push_back({b[i].fi,{b[i].se,i}});
    }
    sort(a.begin(),a.end());
    sort(order.begin(),order.end());
    for(int i = 1; i <= n; i++) ok[i] = 0;
    for(int i = 0; i < order.size(); i++) {
        dfs(order[i].se.fi,order[i].se.se);
    }
    for(int i = 1; i <= n; i++) ok[i] = 0;
    for(int i = order.size()-1; i >= 0; i--) {
        dfs(order[i].se.fi,order[i].se.se);
    }
    for(int i = a.size()-1; i >= 0; i--) {
        if(ans[a[i].se].fi == -1) cout << 0 << endl;
        else cout << abs(ans[a[i].se].fi-ans[a[i].se].se)+1 << endl;
    }
    return 0;
}

Compilation message

tra.cpp: In function 'void check()':
tra.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i = 0; i < a.size(); i++) {
      |                    ~~^~~~~~~~~~
tra.cpp: In function 'int main()':
tra.cpp:83:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for(int i = 0; i < b.size(); i++) {
      |                    ~~^~~~~~~~~~
tra.cpp:89:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     for(int i = 0; i < order.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14672 KB Output is correct
2 Correct 3 ms 14672 KB Output is correct
3 Correct 3 ms 14672 KB Output is correct
4 Incorrect 3 ms 14672 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14672 KB Output is correct
2 Incorrect 3 ms 14828 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 14848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 14928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 17896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 19916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 22352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 66 ms 24392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 116 ms 28164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 212 ms 36808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 533 ms 48608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 110 ms 27588 KB Output isn't correct
2 Halted 0 ms 0 KB -