RT, which is a strong component of China Unicom.
And I love a Hungarian OIer
quietly Qiaoxia ...
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
int n,m,cnt,vis[100005],match[100005],head[100005],now[100005];
map<string,int> boy,girl;
struct edge{
int u,v,next;bool dis;
}e[100005];
inline void add(int u,int v){
e[++cnt].v=v;
e[cnt].u=u;
e[cnt].next=head[u];
head[u]=cnt;
}
inline bool dfs(int u){
for(int i=head[u];i!=-1;i=e[i].next){
if(e[i].dis)continue;
int v=e[i].v;
if(!vis[v]){
vis[v]=1;
if(match[v]==-1||dfs(match[v])){
match[v]=u;
return 1;
}
}
}
return 0;
}
int main(){
memset(match,-1,sizeof(match));
memset(head,-1,sizeof(head));
scanf("%d",&n);
for(int i=1;i<=n;i++){
string s,t;
cin>>s>>t;
boy[s]=i;
girl[t]=i;
add(boy[s],girl[t]);
now[i]=cnt;
}
scanf("%d",&m);
for(int i=1;i<=m;i++){
string s,t;
cin>>s>>t;
add(boy[s],girl[t]);
}
for(int i=1;i<=n;i++){
memset(match,-1,sizeof(match));
int tot=0;
e[now[i]].dis=1;
for(int j=1;j<=n;j++){
memset(vis,0,sizeof(vis));
tot+=dfs(j);
}
if(tot==n){
printf("Unsafe\n");
}
else{
printf("Safe\n");
}
e[now[i]].dis=0;
}
}
TLE accident scene
Then various constants optimized
register NM's, hash, read optimization
P with what was
then look through the valley of Los solution to a problem
is probably basically strong Unicom components
but there is a is a bipartite graph
and regain the confidence of QwQ
but who Giant bipartite graph diagram guys is to build characters and sister uniform number, I did not used to
it can not be copied solution to a problem, I just had to
after the crash mentality carefully read explanations giant guys who
find the root! this! Do not! Yes! General bipartite graph wording
because the beginning is a good match
with my code is:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
int n,m,cnt,vis[100005],match[100005],head[100005],dis;
map<string,int> boy,girl;
struct edge{
int u,v,next;
}e[100005];
inline void add(int u,int v){
e[++cnt].v=v;
e[cnt].u=u;
e[cnt].next=head[u];
head[u]=cnt;
}
inline bool dfs(int u){
for(int i=head[u];i!=-1;i=e[i].next){
int v=e[i].v;
if(u==dis&&v==dis)continue;
if(!vis[v]){
vis[v]=1;
if(match[v]==-1||dfs(match[v])){
return 1;
}
}
}
return 0;
}
int main(){
memset(match,-1,sizeof(match));
memset(head,-1,sizeof(head));
scanf("%d",&n);
for(int i=1;i<=n;i++){
string s,t;
cin>>s>>t;
boy[s]=i;
girl[t]=i;
match[i]=i;
}
scanf("%d",&m);
for(int i=1;i<=m;i++){
string s,t;
cin>>s>>t;
add(boy[s],girl[t]);
}
for(int i=1;i<=n;i++){
memset(vis,0,sizeof(vis));
match[i]=-1;
dis=i;
if(dfs(i)){
printf("Unsafe\n");
}
else{
printf("Safe\n");
}
match[i]=i;
}
}