#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAXN = 2e5 + 10;
int n, m, h[MAXN];
vector <pair<int,int>> pt, adj[MAXN], ofo, amo, all[MAXN]; //ofo=y,amo=x
queue <int> q;
bool inq[MAXN];
inline void addedge(){
for(int i = 0; i < n; i++){
if(all[i].empty()) continue;
sort(all[i].begin(), all[i].end()); all[i].push_back(all[i][0]);
/*cout << "i:" << i+1 << '\n';
for(auto j: all[i]) cout << j.first << ":" << j.second << " ";
cout << endl << endl;*/
for(int j = 0; j < (int)all[i].size()-1; j++){
int id = all[i][j].second, di = all[i][j].first, id2 = all[i][j+1].second, di2 = all[i][j+1].first;
int t1 = (di==3||di==2), t2 = (di2==3||di2==2); //0->{1,0} 1->{3,2}
if(t1 && !t2){
adj[id].push_back({id2,0});
adj[id2].push_back({id,0});
}
if(t1 && t2){
adj[id].push_back({id2+m,0});
adj[id2+m].push_back({id,0});
}
if(!t1 && !t2){
adj[id+m].push_back({id2,0});
adj[id2].push_back({id+m,0});
}
if(!t1 && t2){
adj[id+m].push_back({id2+m,0});
adj[id2+m].push_back({id+m,0});
}
}
all[i].clear();
}
for(int i = 0; i < m; i++){
adj[i].push_back({i+m,1});
adj[i+m].push_back({i,1});
}
return;
}
inline void slv(int r){
/* set <pair<int,int>> st; h[r] = 0;
st.insert({0,r});
while(!st.empty()){
int v = st.begin()->second; st.erase(*st.begin());
for(auto i: adj[v]){
int u = i.first, ww = i.second;
if(h[u] > h[v]+ww){
st.erase({h[u],u});
h[u] = h[v]+ww;
st.insert({h[u],u});
}
}
}*/
h[r] = 0; q.push(r); inq[r] = true;
while(!q.empty()){
int v = q.front(); q.pop(); inq[v] = false;
for(auto i: adj[v]){
int u = i.first, ww = i.second;
if(h[u] > h[v]+ww){
h[u] = h[v]+ww;
if(!inq[u]) q.push(u);
inq[u] = true;
}
}
}
return;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
for(int i = 0; i < MAXN; i++) h[i] = INT_MAX;
cin >> n;
for(int i = 0; i < n; i++){
int xx,yy;
cin >> xx >> yy;
pt.push_back({xx,yy});
}
cin >> m;
for(int i = 0; i < m; i++){
int u, v;
cin >> u >> v; u--; v--;
if(pt[u].first==pt[v].first){
amo.push_back({pt[u].first,i});
if(pt[u].second > pt[v].second) swap(u,v);
all[u].push_back({2,i});
all[v].push_back({0,i});
}
else{
ofo.push_back({pt[u].second,i});
if(pt[u].first > pt[v].first) swap(u,v);
all[u].push_back({1,i});
all[v].push_back({3,i});
}
}
addedge();
sort(ofo.begin(), ofo.end());
sort(amo.begin(), amo.end());
for(auto i: ofo)
if(h[i.second] >= INT_MAX) slv(i.second);
for(auto i: amo)
if(h[i.second] >= INT_MAX) slv(i.second);
vector <int> ans;
for(int i = 0; i < m; i++)
if(h[i] == h[i+m]) ans.push_back(i);
cout << (int)ans.size() << '\n';
for(auto i: ans) cout << i+1 <<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10488 KB |
Output is correct |
2 |
Correct |
7 ms |
10476 KB |
Output is correct |
3 |
Correct |
7 ms |
10476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10604 KB |
Output is correct |
2 |
Correct |
8 ms |
10624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10476 KB |
Output is correct |
2 |
Correct |
7 ms |
10476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
10476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10604 KB |
Output is correct |
2 |
Correct |
8 ms |
10604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10604 KB |
Output is correct |
2 |
Correct |
9 ms |
10604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
14576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
25704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
26600 KB |
Output is correct |
2 |
Runtime error |
132 ms |
36200 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
106 ms |
33512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
125 ms |
36072 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |