結果
| 問題 |
No.2319 Friends+
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2023-05-26 21:43:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 513 ms / 3,000 ms |
| コード長 | 1,358 bytes |
| コンパイル時間 | 3,619 ms |
| コンパイル使用メモリ | 261,208 KB |
| 最終ジャッジ日時 | 2025-02-13 06:17:40 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 45 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
26 | scanf("%d %d",&u,&v);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:55:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
55 | scanf("%d %d",&a,&b);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
#define sq 1300
int main(){
int N,M;
cin>>N>>M;
vector<int> p(N);
rep(i,N){
cin>>p[i];
p[i]--;
}
vector<vector<int>> E(N);
rep(i,M){
int u,v;
scanf("%d %d",&u,&v);
u--,v--;
E[u].push_back(v);
E[v].push_back(u);
}
vector<int> big(N);
rep(i,N){
if(E[i].size()>sq)big[i] = 1;
}
vector<vector<int>> nE(N);
rep(i,N){
rep(j,E[i].size()){
if(big[E[i][j]])nE[i].push_back(E[i][j]);
}
}
vector<map<int,int>> mp(N);
rep(i,N){
rep(j,nE[i].size()){
int to = nE[i][j];
mp[to][p[i]]++;
}
}
int q;
cin>>q;
rep(_,q){
int a,b;
scanf("%d %d",&a,&b);
a--,b--;
if(p[a]==p[b]){
cout<<"No"<<endl;
continue;
}
bool f = false;
if(big[a]){
if(mp[a].count(p[b]))f = true;
}
else{
rep(i,E[a].size()){
int to = E[a][i];
if(p[to]==p[b])f = true;
}
}
if(!f){
cout<<"No"<<endl;
continue;
}
cout<<"Yes"<<endl;
rep(i,nE[a].size()){
int to = nE[a][i];
mp[to][p[a]]--;
if(mp[to][p[a]]==0)mp[to].erase(p[a]);
}
p[a] = p[b];
rep(i,nE[a].size()){
int to = nE[a][i];
mp[to][p[a]]++;
}
}
return 0;
}
沙耶花