結果

問題 No.1817 Reversed Edges
ユーザー 蜜蜂蜜蜂
提出日時 2022-01-21 21:34:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,786 bytes
コンパイル時間 3,921 ms
コンパイル使用メモリ 230,976 KB
実行使用メモリ 20,096 KB
最終ジャッジ日時 2024-05-04 12:07:27
合計ジャッジ時間 7,420 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 145 ms
11,044 KB
testcase_23 AC 154 ms
11,008 KB
testcase_24 AC 153 ms
20,096 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:75:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   75 |     auto [a,b]=v[i];
      |          ^

ソースコード

diff #

//g++ 1.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;

#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

void dfs(int now,int par,vi &dist,vvi &g){
  for(int next:g[now]){
    if(next==par)continue;
    dist[next]=dist[now]+1;
    dfs(next,now,dist,g);
  }
}

void dfs2(int now,int par,vi &del,vi &ans,vvi &g,int &val){
  val+=del[now];
  ans[now]=val;

  for(int next:g[now]){
    if(next==par)continue;
    dfs2(next,now,del,ans,g,val);
  }

  val-=del[now];
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin>>n;

  vvi g(n);
  vi dist(n,0);
  vector<pair<int,int>> v(n-1);
  rep(i,0,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
    v[i]={a,b};
  }

  dfs(0,-1,dist,g);

  vi del(n,0);
  vi ans(n,0);

  rep(i,0,n-1){
    auto [a,b]=v[i];
    if(a>b){
      swap(a,b);
    }

    // dist[a]<dist[b] b側 +1
    // dist[a]>dist[b] a側 +1 = 全体 +1 - b側 +1

    if(dist[a]<dist[b]){
      del[b]++;
    }
    else{
      del[0]++;
      del[b]--;
    }
  }

  int val=0;
  dfs2(0,-1,del,ans,g,val);

  rep(i,0,n){
    cout<<ans[i]<<endl;
  }
}
0