ログイン
新規登録
AtsuoCoder Petrozavodsk Contest 001
読込中…
Home
Tasks
Clar
Submissions
Standings
提出 878d21b8-aa31-4ad4-816c-9cdf23f696d8
コード
#ifndef MAIN #define MAIN #include __FILE__ #define mp make_pair string toup(string s) { rep(i, s.at(i)) { if (s.at(i) >= 'a' && s.at(i) <= 'z') { s.at(i) -= 32; } } return s; } string tolow(string s) { rep(i, s.at(i)) { if (s.at(i) >= 'A' && s.at(i) <= 'Z') { s.at(i) += 32; } } return s; } bool isPalindrome(const std::string& str) { int left = 0; int right = str.size() - 1; while (left < right) { if (str[left] != str[right]) { return false; } ++left; --right; } return true; } void _main() { cint(n,m); map<int, set<int>> graph; rep(i,m){ cint(a,b); graph[a].insert(b); graph[b].insert(a); } cint(q); rep(i,q){ cint(command); if(command==1){ cint(s,t); graph[s].erase(t); graph[t].erase(s); } else if(command==2){ cint(s,t); vector<bool> visited(n+1,false); queue<int> que; que.push(s); while(!que.empty()){ int place = que.front(); que.pop(); visited[place]=true; for (int x : graph[place]){ if(!visited[x]){ que.push(x); } } } if(visited[t]){ cout<<"Yes"<<endl; } else cout<<"No"<<endl; } else if(command==3){ cint(s); vector<bool> visited(n+1,false); queue<int> que; que.push(s); while(!que.empty()){ int place = que.front(); visited[place]=true; que.pop(); for (int x : graph[place]){ if(!visited[x]){ que.push(x); } } } rep(i,n){ if(visited[i+1]){ cout<<i+1<<" "; } } cout<<endl; } else if(command==4){ cint(s); vector<bool> visited(n+1,false); int ppl=0; queue<int> que; que.push(s); while(!que.empty()){ int place = que.front(); ppl++; visited[place]=true; que.pop(); for (int x : graph[place]){ if(!visited[x]){ que.push(x); } } } cout<<ppl<<endl; } else{ cint(s,t); graph[s].insert(t); graph[t].insert(s); } } } #else #define MAIN //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #if __has_include(<bits/stdc++.h>) #include <bits/stdc++.h> #else import std; #endif #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; using modint10 = modint1000000007; using motint9 = modint998244353; #endif using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<string> strvec; constexpr ll mod10 = 1000000007; constexpr ll mod9 = 998244353; constexpr ll inf = 10000000000000000; #define int ll #define double ld #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repf(i, s, n) for (int i = s; i < (int)(n); i++) template <class... Args> void __y_input(Args &...arg) { (cin >> ... >> arg); } template <class... Args> void __y_input_vec_1(int p, Args &...args) { (cin >> ... >> args[p]); } template <class Arg> void __y_input_vec_resize(int size, Arg& arg) { arg.resize(size); } template <class... Args> void __y_input_vec(int n, Args &...args) { (__y_input_vec_resize(n, args), ...); rep(i, n) { (__y_input_vec_1(i, args), ...); } } #define cint(...) \ int __VA_ARGS__; \ __y_input(__VA_ARGS__) #define cdbl(...) \ double __VA_ARGS__; \ __y_input(__VA_ARGS__) #define cstr(...) \ string __VA_ARGS__; \ __y_input(__VA_ARGS__) #define cit(t, ...) \ t __VA_ARGS__; \ __y_input(__VA_ARGS__) #define cvec(n, ...) \ vector<int> __VA_ARGS__; \ __y_input_vec(n, __VA_ARGS__) #define cvect(t, n, ...) \ vector<t> __VA_ARGS__; \ __y_input_vec(n, __VA_ARGS__) #define last cout << endl #define yn(bl) (bl ? "Yes" : "No") ostream& yesno(bool bl) { cout << yn(bl); return cout; } typedef array<int, 2> xy; typedef array<int, 3> xyz; template <typename T> inline void sort(T& vec) { return sort(vec.begin(), vec.end()); } template <typename T> inline void rsort(T& vec) { return sort(vec.rbegin(), vec.rend()); } namespace __yc { template <typename T> struct __set : public std::set<T> { inline void Merge(set<T>& other) { if (this->size() < other.size()) { other.merge(*this); swap(*this, other); } else { this->merge(other); } return; } }; template <typename T> struct set : public __set<T> { inline void merge(set<T>& other) { this->Merge(other); } }; } #define set __yc::set void _main(); signed main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); _main(); return 0; } #endif
結果
問題
点数
言語
結果
実行時間
メモリ
G - Breaking Friends
50
C++
TLE
3105 ms
34828 KiB