結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-19 11:44:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,025 bytes |
| コンパイル時間 | 1,977 ms |
| コンパイル使用メモリ | 103,556 KB |
| 実行使用メモリ | 9,340 KB |
| 最終ジャッジ日時 | 2024-06-12 20:54:09 |
| 合計ジャッジ時間 | 6,090 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 48 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:107:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
107 | int n, m; scanf("%d%d", &n,&m);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:111:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
111 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
main.cpp:113:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
113 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
main.cpp: In member function ‘void Do_you_wanna_be_a_friend_of_mine::getFriends()’:
main.cpp:76:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
76 | scanf("%d%d", &p, &q); p--; q--;
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <list>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;
using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(0, -1)};
constexpr char BR = '\n';
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())
template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
if(n == 0) return "0";
std::string res = "";
if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
std::reverse(res.begin(), res.end()); return '-' + res;}
while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class Do_you_wanna_be_a_friend_of_mine{
private:
const int n, m;
std::vector<Vint> Friends;
std::vector<bool> HasntVisited;
public:
Do_you_wanna_be_a_friend_of_mine(int nn, int mm): n(nn), m(mm){
Friends.resize(n, Vint(0));
HasntVisited.resize(n);
}
~Do_you_wanna_be_a_friend_of_mine(void){};
void getFriends(void){
int p, q;
REP(i, m){
scanf("%d%d", &p, &q); p--; q--;
Friends.at(p).emplace_back(q);
Friends.at(q).emplace_back(p);
}
}
std::pair<int, int> solve(int a){
a--; REP(i, n) HasntVisited[i] = true;
int numb = -1, height;
std::queue<std::pair<int, int>> dfs;
HasntVisited.at(a) = false;
dfs.push(make_pair(a, 0));
int now;
while(not dfs.empty()){
std::tie(now, height) = dfs.front(); dfs.pop();
vREP(friend_next, Friends.at(now)) if(HasntVisited.at(friend_next)){
HasntVisited.at(friend_next) = false;
dfs.push(make_pair(friend_next, height + 1));
}
numb++;
}
// heght := 1 => 0
// := 2 => 1
// := 3 => 2
// := 4 => 2
return make_pair(numb, (height <= 1) ? 0 : (height + 1) / 2);
}
};
int main(void){
int n, m; scanf("%d%d", &n,&m);
Do_you_wanna_be_a_friend_of_mine solver(n, m);
solver.getFriends();
int a, q, s, t;
scanf("%d", &q);
REP(_, q){
scanf("%d", &a);
std::tie(s, t) = solver.solve(a);
printf("%d %d\n", s, t);
}
return 0;
}