# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1111657 |
2024-11-12T13:35:47 Z |
vjudge1 |
Traffic (CEOI11_tra) |
C++17 |
|
424 ms |
55624 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];
int cnt = 1;
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;
//cout << v2[s].size() << 'k' << endl;
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();
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:31: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]
31 | for(int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
tra.cpp: In function 'int main()':
tra.cpp:86: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]
86 | for(int i = 0; i < b.size(); i++) {
| ~~^~~~~~~~~~
tra.cpp:92: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]
92 | for(int i = 0; i < order.size(); i++) {
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
14672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
14672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
14672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
14856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
15952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
18240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
21576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
23928 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
142 ms |
29976 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
201 ms |
37448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
424 ms |
55624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
102 ms |
30548 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |