#37465: 第二筆測資WA


samlin961112@gmail.com (林哲甫)

學校 : 新北市私立南山高級中學
編號 : 220506
來源 : [219.70.213.92]
最後登入時間 :
2024-04-28 22:43:43
b298. 老闆阿我要退貨 -- 103學年度板橋高中校內資訊學科能力競賽(一) | From: [219.70.213.92] | 發表日期 : 2023-09-12 00:29

#include <bits/stdc++.h>
using namespace std;
int a[10001];
bool z[10001];
bool dfs(int i){
  if(z[i]||z[a[i]]){
    return true;
  }else if(a[i]==i){
    return false;
  }else{
    return dfs(a[a[i]]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n,m,l,q;
  cin>>n>>m>>l>>q;
  
  for(int i=0;i<n+1;i++){
    a[i]=i;
    z[i]=false;
  }
  for(int i=0;i<m;i++){
    int w,s;
    cin>>w>>s;
    a[s]=w;
  }
  for(int i=0;i<l;i++){
    int w;
    cin>>w;
    z[w]=true;
  }
  for(int i=0;i<n+1;i++){ 
    if(dfs(i)){
      z[i]=true;
    }
  }
  for(int i=0;i<q;i++){
    int w;
    cin>>w;
    if(z[w]){
      cout<<"TUIHUOOOOOO\n";
    }else{
      cout<<"YA~~\n";
    }
  }
}

 
#37478: Re: 第二筆測資WA


samlin961112@gmail.com (林哲甫)

學校 : 新北市私立南山高級中學
編號 : 220506
來源 : [219.70.213.92]
最後登入時間 :
2024-04-28 22:43:43
b298. 老闆阿我要退貨 -- 103學年度板橋高中校內資訊學科能力競賽(一) | From: [219.70.213.92] | 發表日期 : 2023-09-12 21:59

#include
using namespace std;
int a[10001];
bool z[10001];
bool dfs(int i){
  if(z[i]||z[a[i]]){
    return true;
  }else if(a[i]==i){
    return false;
  }else{
    return dfs(a[a[i]]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n,m,l,q;
  cin>>n>>m>>l>>q;
  
  for(int i=0;i
    a[i]=i;
    z[i]=false;
  }
  for(int i=0;i
    int w,s;
    cin>>w>>s;
    a[s]=w;
  }
  for(int i=0;i
    int w;
    cin>>w;
    z[w]=true;
  }
  for(int i=0;i

發現錯誤了,已AC

 
ZeroJudge Forum