# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
114218 | evpipis | Port Facility (JOI17_port_facility) | C++17 | 6079 ms | 366888 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
const int len = 2e5+5, mod = 1e9+7;
int order[len], vis[len];
ii ran[len];
vector<int> adj[len], st;
int dfs(int u, int t){
vis[u] = t;
int ans = 1;
for (int j = 0; j < adj[u].size(); j++){
int v = adj[u][j];
if (vis[v] == t)
ans = 0;
if (vis[v] == -1)
ans *= dfs(v, 1-t);
}
//printf("dfs(%d, %d) = %d\n", u, t, ans);
return ans;
}
int main(){
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++){
scanf("%d %d", &ran[i].fi, &ran[i].se);
order[ran[i].fi] = -i;
order[ran[i].se] = i;
}
for (int i = 1; i <= 2*n; i++){
int cur = order[i];
if (cur > 0){
int pos = st.size()-1;
while (st[pos] != cur){
adj[cur].pb(st[pos]);
adj[st[pos]].pb(cur);
//printf("edge: %d, %d\n", cur, st[pos]);
pos--;
}
st.erase(st.begin()+pos);
}
else{
cur = -cur;
st.pb(cur);
}
}
for (int i = 1; i <= n; i++)
vis[i] = -1;
int po = 0, no = 0;
for (int i = 1; i <= n; i++){
if (vis[i] != -1)
continue;
if (dfs(i, 0))
po++;
else
no = 1;
}
if (no){
printf("0\n");
}
else{
int temp = 1;
for (int i = 0; i < po; i++)
temp = (2*temp)%mod;
printf("%d\n", temp);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |