QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#341112 | #997. 2-SAT 问题 | Kevin5307# | WA | 122ms | 26000kb | C++20 | 1.4kb | 2024-02-29 15:50:43 | 2024-02-29 15:50:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
vector<int> G[1200200],rG[1200200],nG[1200200];
vector<int> order;
int vis[1200200],scc[1200200],cnt,ord[1200200],tot;
int indeg[1200200];
void dfs1(int u)
{
vis[u]=1;
for(auto v:G[u])
if(!vis[v])
dfs1(v);
order.push_back(u);
}
void dfs2(int u)
{
scc[u]=cnt;
for(auto v:rG[u])
if(!scc[v])
dfs2(v);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int a,b,c,d;
cin>>a>>b>>c>>d;
G[(b^1)*n+a].push_back(d*n+c);
G[(d^1)*n+c].push_back(b*n+a);
}
for(int i=1;i<=n+n;i++)
for(auto j:G[i])
rG[j].push_back(i);
for(int i=1;i<=n;i++)
if(!vis[i])
dfs1(i);
reverse(order.begin(),order.end());
for(auto x:order)
if(!scc[x])
{
cnt++;
dfs2(x);
}
for(int i=1;i<=n;i++)
if(scc[i]==scc[i+n])
{
cout<<"No"<<endl;
return 0;
}
for(int i=1;i<=n+n;i++)
for(auto j:G[i])
if(scc[i]!=scc[j])
{
nG[scc[i]].push_back(scc[j]);
indeg[scc[j]]++;
}
queue<int> q;
for(int i=1;i<=cnt;i++)
if(!indeg[i])
q.push(i);
while(!q.empty())
{
int x=q.front();
q.pop();
ord[x]=++tot;
for(auto y:nG[x])
{
indeg[y]--;
if(!indeg[y])
q.push(y);
}
}
cout<<"Yes"<<endl;
for(int i=1;i<=n;i++)
cout<<(ord[scc[i]]<ord[scc[i+n]])<<" ";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 69ms
memory: 26000kb
input:
86354 86418 14615 0 14903 1 13605 0 4458 0 15604 0 77112 0 52311 1 64996 0 22711 1 74245 1 39042 1 57372 1 2994 1 84183 1 80574 0 58791 1 27780 1 9336 1 61809 0 7216 0 71113 0 42287 1 20073 0 72448 0 73840 0 77048 0 28955 0 4165 0 16322 1 14075 1 43512 0 58600 1 45219 0 53858 0 14919 0 22576 0 16594...
output:
Yes 1 1 1 1 1 1 0 1 1 1 1 1 1 0 0 0 0 0 1 0 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 0 0 0 1 0 1 1 0 0 1 0 0 1 0 1 1 1 1 0 1 0 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 0 0 0 0 1 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 0 0 1 1 1 1 0 1 0 1 0 0 1 0 1 1 0 1 1 1 1 1 0 1 1 ...
result:
ok Good plan
Test #2:
score: 0
Accepted
time: 76ms
memory: 12776kb
input:
17625 186889 17290 0 17616 1 8909 0 15829 0 9807 0 9920 1 14912 0 3052 1 14426 0 16910 1 8910 1 10153 1 5163 1 1118 1 2764 0 2787 1 2998 0 2344 1 17573 1 5693 1 9120 0 4529 1 9836 0 4832 0 4021 0 16206 1 1109 0 13286 1 12402 1 16982 0 6311 1 1218 1 147 0 5411 0 3958 1 1571 0 4848 1 16678 0 7433 1 31...
output:
Yes 1 0 0 1 0 1 1 1 1 1 0 1 1 1 1 0 1 0 0 0 1 0 0 1 0 1 1 1 1 0 0 0 1 1 0 1 1 1 1 0 1 0 0 0 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 0 0 0 0 1 0 0 0 1 1 0 0 1 0 1 1 0 0 1 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 1 0 1 0 0 1 1 0 0 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 1 1 1 1 1 0 0 1 0 0 0 0 1 1 0 1 ...
result:
ok Good plan
Test #3:
score: 0
Accepted
time: 80ms
memory: 14556kb
input:
27276 180666 4575 1 13941 1 23689 1 276 1 8916 1 5504 1 10230 1 19907 1 15820 1 27258 0 18040 0 11405 0 23944 1 23049 1 12183 1 24927 0 26509 1 20881 0 14596 1 766 0 5071 1 10703 0 15926 1 25575 1 15486 1 35 0 11290 1 26937 0 3475 0 20672 1 10309 0 22343 1 22873 0 21025 0 14802 1 22377 0 7701 1 1185...
output:
Yes 0 1 0 0 0 0 1 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1 0 1 1 1 1 1 0 1 1 0 1 1 0 0 0 1 1 1 1 0 0 1 0 0 1 0 0 1 1 1 0 1 1 1 0 1 1 0 0 1 0 1 1 1 1 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 ...
result:
ok Good plan
Test #4:
score: 0
Accepted
time: 80ms
memory: 23480kb
input:
70213 93094 53616 1 59247 1 16687 0 63568 0 10114 1 55521 1 58830 1 22082 0 46298 0 65072 0 2622 1 16071 0 66725 0 46161 1 4204 1 7255 0 39103 1 19710 1 33819 1 19406 0 24055 1 6494 1 45844 0 59888 0 63714 1 30868 0 12762 0 43441 0 59330 1 35278 0 2212 0 1284 0 45959 1 17786 1 17744 0 66761 1 54970 ...
output:
Yes 0 1 0 0 1 1 1 1 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 1 0 0 1 0 1 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 1 0 1 0 0 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1 0 1 0 0 1 1 1 0 1 1 ...
result:
ok Good plan
Test #5:
score: 0
Accepted
time: 122ms
memory: 23084kb
input:
66484 178501 3057 1 32192 1 19941 0 37367 1 56292 0 54533 0 20407 1 27938 1 28653 1 37219 1 64377 0 63482 0 25218 0 12814 1 29736 0 34360 0 61150 0 38346 1 1116 0 56594 0 7410 1 58121 1 41370 0 36704 0 23807 1 60815 1 63396 0 55650 1 26564 1 5193 0 65150 1 27578 0 13215 0 5871 0 56406 1 63683 0 1321...
output:
No
result:
ok No Solution
Test #6:
score: 0
Accepted
time: 39ms
memory: 10224kb
input:
9650 160962 4804 1 3956 0 4557 0 7207 1 4157 1 7867 0 1045 0 5033 0 8623 0 5770 1 4090 1 3088 1 2846 0 8117 1 4827 1 474 0 2822 0 4035 1 2245 1 4894 0 5093 0 8553 1 9160 1 641 1 5302 1 7701 1 4246 0 718 0 2096 1 2709 1 4288 0 850 1 4262 0 1309 0 2713 1 286 0 7228 1 5945 1 7481 0 770 1 1617 1 4784 1 ...
output:
Yes 1 1 0 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 1 0 1 0 0 0 1 0 0 1 1 1 0 1 0 1 0 1 0 0 1 1 0 0 1 1 1 1 1 1 0 0 1 0 0 1 0 0 0 1 1 0 1 0 1 1 1 0 0 1 0 1 1 1 1 1 0 1 1 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 0 0 1 0 0 1 1 1 1 0 1 0 0 0 0 1 0 0 0 0 1 1 1 ...
result:
ok Good plan
Test #7:
score: -100
Wrong Answer
time: 89ms
memory: 21828kb
input:
82878 170546 59669 0 52924 1 4674 1 27496 0 81463 1 82234 0 22606 0 30346 1 70787 1 16429 0 46983 0 80599 0 82208 0 51421 1 31035 0 74680 0 48903 1 55211 1 46935 1 76651 1 78465 0 18656 0 55607 1 13210 1 14749 1 25929 0 69893 1 23187 1 8840 0 5696 1 30898 1 14164 0 55439 1 68798 0 29324 1 6831 1 103...
output:
No
result:
wrong answer You didn't find a solution but jury did.