AtCoder Regular Contest 022

Submission #1005310

Source codeソースコード

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int n;
deque<bool> reached;
vvi g;

vvi result;
void dfs(vi d_v) {
  int d = d_v[0];
  int v = d_v[1];
  vi ret = {d, v}; // distance, node
  reached[v] = true;
  result.pb(d_v);
  for (int node : g[v]) {
    if (!reached[node]) {
      dfs({d+1, node});
    }
  }
}

int main() {
  scanf("%d", &n);
  g.resize(n);
  rep (i, n-1) {
    int a, b;
    scanf("%d%d", &a, &b);
    a -= 1; b -= 1;
    g[a].pb(b);
    g[b].pb(a);
  }

  reached.assign(n, false);
  dfs({0, 0});
  sort(all(result));
  int len;
  len = result.size();
  int x = result[len-1][1];

  reached.assign(n, false);
  result.clear();
  dfs({0, x});
  sort(all(result));
  len = result.size();
  int y = result[len-1][1];
  printf("%d %d\n", x + 1, y + 1);

  return 0;
}

Submission

Task問題 C - ロミオとジュリエット
User nameユーザ名 cyglef
Created time投稿日時
Language言語 C++11 (GCC 4.8.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 1732 Byte
File nameファイル名
Exec time実行時間 171 ms
Memory usageメモリ使用量 29012 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:59:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:63:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a, &b);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt
Subtask1 40 / 40 sample_01.txt,sample_02.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt
Subtask2 60 / 60 subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt,subtask2_01.txt,subtask2_02.txt,subtask2_03.txt,subtask2_04.txt,subtask2_05.txt,subtask2_06.txt,subtask2_07.txt,subtask2_08.txt,subtask2_09.txt,subtask2_10.txt,subtask2_11.txt,subtask2_12.txt,subtask2_13.txt,subtask2_14.txt,subtask2_15.txt,subtask2_16.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 16 ms 928 KB
sample_02.txt AC 18 ms 792 KB
subtask1_01.txt AC 16 ms 792 KB
subtask1_02.txt AC 16 ms 672 KB
subtask1_03.txt AC 18 ms 800 KB
subtask1_04.txt AC 18 ms 800 KB
subtask1_05.txt AC 18 ms 796 KB
subtask1_06.txt AC 16 ms 928 KB
subtask1_07.txt AC 16 ms 800 KB
subtask1_08.txt AC 18 ms 800 KB
subtask1_09.txt AC 18 ms 800 KB
subtask1_10.txt AC 19 ms 924 KB
subtask1_11.txt AC 19 ms 1052 KB
subtask1_12.txt AC 17 ms 800 KB
subtask1_13.txt AC 19 ms 928 KB
subtask1_14.txt AC 17 ms 800 KB
subtask1_15.txt AC 18 ms 924 KB
subtask1_16.txt AC 19 ms 796 KB
subtask1_17.txt AC 17 ms 800 KB
subtask1_18.txt AC 18 ms 920 KB
subtask2_01.txt AC 28 ms 2080 KB
subtask2_02.txt AC 133 ms 10836 KB
subtask2_03.txt AC 143 ms 11216 KB
subtask2_04.txt AC 125 ms 10536 KB
subtask2_05.txt AC 113 ms 9940 KB
subtask2_06.txt AC 157 ms 27856 KB
subtask2_07.txt AC 46 ms 4140 KB
subtask2_08.txt AC 52 ms 4396 KB
subtask2_09.txt AC 171 ms 29012 KB
subtask2_10.txt AC 133 ms 12168 KB
subtask2_11.txt AC 132 ms 12104 KB
subtask2_12.txt AC 154 ms 11856 KB
subtask2_13.txt AC 153 ms 11856 KB
subtask2_14.txt AC 154 ms 11952 KB
subtask2_15.txt AC 156 ms 11856 KB
subtask2_16.txt AC 151 ms 11860 KB