結果

問題 No.416 旅行会社
ユーザー ei1333333ei1333333
提出日時 2016-07-21 22:37:59
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,466 bytes
コンパイル時間 1,510 ms
コンパイル使用メモリ 174,860 KB
実行使用メモリ 27,976 KB
最終ジャッジ日時 2024-04-25 13:31:11
合計ジャッジ時間 6,857 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
21,828 KB
testcase_01 AC 3 ms
9,156 KB
testcase_02 AC 4 ms
8,904 KB
testcase_03 AC 4 ms
9,540 KB
testcase_04 AC 3 ms
9,284 KB
testcase_05 AC 3 ms
8,900 KB
testcase_06 AC 4 ms
9,156 KB
testcase_07 AC 4 ms
10,696 KB
testcase_08 AC 6 ms
10,056 KB
testcase_09 AC 17 ms
10,692 KB
testcase_10 AC 122 ms
21,700 KB
testcase_11 AC 142 ms
21,704 KB
testcase_12 AC 145 ms
21,704 KB
testcase_13 AC 122 ms
21,700 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 RE -
testcase_20 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:40:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |   scanf("%d %d %d", &N, &M, &Q);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:44:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |     scanf("%d %d", &A[i], &B[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:48:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |     scanf("%d %d", &C[i], &D[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef pair< int, int > Pi;
 
int data[100000];
set< int > zig[100000];
int query[100000];
 
int find(int y)
{
  if(data[y] < 0) return(y);
  return(data[y] = find(data[y]));
}
void unite(int x, int y)
{
  x = find(x);
  y = find(y);
  if(x != y) {
    if(zig[x].size() < zig[y].size()) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    while(!zig[y].empty()) {
      zig[x].insert(*zig[y].begin());
      zig[y].erase(zig[y].begin());
    }
  }
}
 
 
int N, M, Q;
bool v[100000];
int A[100000], B[100000];
int C[100000], D[100000];
 
map< Pi, int > idx;
 
int main()
{
  memset(data, -1, sizeof(data));
  scanf("%d %d %d", &N, &M, &Q);
  for(int i = 0; i < N; i++) zig[i].insert(i);
   
  for(int i = 0; i < M; i++) {
    scanf("%d %d", &A[i], &B[i]);
    idx[minmax(--A[i], --B[i])] = i;
  }
  for(int i = 0; i < Q; i++) {
    scanf("%d %d", &C[i], &D[i]);
    v[idx[minmax(--C[i], --D[i])]] = true;
  }
  for(int i = 0; i < M; i++) {
    if(!v[i]) unite(A[i], B[i]);
  }
   
  while(!zig[find(0)].empty()) {
    query[*zig[find(0)].begin()] = -1;
    zig[find(0)].erase(zig[find(0)].begin());
  }
   
  for(int i = Q - 1; i >= 0; i--) {
    unite(C[i], D[i]);
    if(find(C[i]) == find(0)) {
      while(!zig[find(0)].empty()) {
        query[*zig[find(0)].begin()] = i + 1;
        zig[find(0)].erase(zig[find(0)].begin());
      }
    }
  }
  for(int i = 1; i < N; i++) {
    printf("%d\n", query[i]);
  }
}
0