# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
197613 |
2020-01-22T02:42:14 Z |
arnold518 |
Traffic (CEOI11_tra) |
C++14 |
|
1305 ms |
72544 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 3e5;
struct Point { int x, y; };
int N, M, A, B;
Point P[MAXN+10];
vector<int> adj[MAXN+10], revadj[MAXN+10], adj2[MAXN+10];
int scc[MAXN+10];
bool vis[MAXN+10];
vector<int> order;
struct Data
{
int l, r;
Data() : l(-1), r(-1) {}
Data(int x) : l(x), r(x) {}
};
Data operator + (const Data &p, const Data &q)
{
if(p.l==-1) return q;
if(q.l==-1) return p;
Data ret;
ret.l=min(p.l, q.l);
ret.r=max(p.r, q.r);
return ret;
}
Data dp[MAXN+10];
vector<int> cand;
void dfs(int now)
{
vis[now]=true;
for(auto nxt : adj[now]) if(!vis[nxt]) dfs(nxt);
order.push_back(now);
}
void dfs2(int now, int col)
{
scc[now]=col;
for(auto nxt : revadj[now]) if(!scc[nxt]) dfs2(nxt, col);
}
void dfs3(int now)
{
vis[now]=true;
if(P[now].x==A) cand.push_back(P[now].y);
for(auto nxt : adj[now]) if(!vis[nxt]) dfs3(nxt);
}
int main()
{
int i, j;
scanf("%d%d%d%d", &N, &M, &A, &B);
for(i=1; i<=N; i++) scanf("%d%d", &P[i].x, &P[i].y);
for(i=1; i<=M; i++)
{
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
adj[u].push_back(v), revadj[v].push_back(u);
if(w==2) adj[v].push_back(u), revadj[u].push_back(v);
}
for(i=1; i<=N; i++) if(!vis[i] && P[i].x==0) dfs3(i);
sort(cand.begin(), cand.end());
cand.erase(unique(cand.begin(), cand.end()), cand.end());
memset(vis, 0, sizeof(vis));
for(i=1; i<=N; i++) if(!vis[i]) dfs(i);
reverse(order.begin(), order.end());
int cnt=0;
for(auto now : order)
{
if(scc[now]) continue;
dfs2(now, ++cnt);
}
for(i=1; i<=N; i++)
{
int now=i;
for(auto nxt : adj[now])
{
if(scc[now]==scc[nxt]) continue;
adj2[scc[now]].push_back(scc[nxt]);
}
}
//for(i=1; i<=N; i++) printf("%d : %d\n", i, scc[i]);
for(i=1; i<=cnt; i++)
{
sort(adj2[i].begin(), adj2[i].end());
adj2[i].erase(unique(adj2[i].begin(), adj2[i].end()), adj2[i].end());
}
for(i=1; i<=N; i++) if(P[i].x==A) dp[scc[i]]=dp[scc[i]]+Data(P[i].y);
for(i=cnt; i>=1; i--)
{
int now=i;
//sort(adj2[now].begin(), adj2[now].end(), [&](const int &p, const int &q) { return pii(dp[p].l, dp[p].r)<pii(dp[q].l, dp[q].r); });
//printf("%d -> ", i);
//for(auto nxt : adj2[i]) printf("%d ", nxt);
//printf("\n");
for(auto nxt : adj2[now]) dp[now]=dp[now]+dp[nxt];
//printf("%d : %d %d %d\n", now, dp[now].l, dp[now].r, dp[now].num);
}
vector<pii> ans;
for(i=1; i<=N; i++) if(P[i].x==0) ans.push_back({P[i].y, upper_bound(cand.begin(), cand.end(), dp[scc[i]].r)-lower_bound(cand.begin(), cand.end(), dp[scc[i]].l)});
sort(ans.begin(), ans.end(), greater<pii>());
for(auto it : ans) printf("%d\n", it.second);
}
Compilation message
tra.cpp: In function 'int main()':
tra.cpp:62:9: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
tra.cpp:64:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &N, &M, &A, &B);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
tra.cpp:65:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=N; i++) scanf("%d%d", &P[i].x, &P[i].y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
tra.cpp:69:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &u, &v, &w);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
24056 KB |
Output is correct |
2 |
Correct |
28 ms |
24184 KB |
Output is correct |
3 |
Correct |
28 ms |
24056 KB |
Output is correct |
4 |
Correct |
26 ms |
24056 KB |
Output is correct |
5 |
Correct |
28 ms |
24184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
24060 KB |
Output is correct |
2 |
Correct |
25 ms |
24184 KB |
Output is correct |
3 |
Correct |
24 ms |
24056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
24060 KB |
Output is correct |
2 |
Correct |
26 ms |
24236 KB |
Output is correct |
3 |
Correct |
25 ms |
24184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
24244 KB |
Output is correct |
2 |
Correct |
31 ms |
24568 KB |
Output is correct |
3 |
Correct |
34 ms |
24568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
25456 KB |
Output is correct |
2 |
Correct |
113 ms |
28920 KB |
Output is correct |
3 |
Correct |
81 ms |
27404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
27388 KB |
Output is correct |
2 |
Correct |
137 ms |
31988 KB |
Output is correct |
3 |
Correct |
103 ms |
30712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
30760 KB |
Output is correct |
2 |
Correct |
270 ms |
38172 KB |
Output is correct |
3 |
Correct |
337 ms |
38124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
278 ms |
31956 KB |
Output is correct |
2 |
Correct |
304 ms |
37292 KB |
Output is correct |
3 |
Correct |
381 ms |
38780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
365 ms |
36816 KB |
Output is correct |
2 |
Correct |
375 ms |
48312 KB |
Output is correct |
3 |
Correct |
715 ms |
51296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
564 ms |
44896 KB |
Output is correct |
2 |
Correct |
681 ms |
62608 KB |
Output is correct |
3 |
Correct |
694 ms |
54256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1175 ms |
52604 KB |
Output is correct |
2 |
Correct |
718 ms |
64356 KB |
Output is correct |
3 |
Correct |
1274 ms |
69584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
310 ms |
37612 KB |
Output is correct |
2 |
Correct |
772 ms |
69224 KB |
Output is correct |
3 |
Correct |
1068 ms |
66256 KB |
Output is correct |
4 |
Correct |
1305 ms |
72544 KB |
Output is correct |