結果

問題 No.416 旅行会社
ユーザー ei1333333ei1333333
提出日時 2016-07-22 00:26:09
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,374 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 170,696 KB
実行使用メモリ 812,744 KB
最終ジャッジ日時 2024-04-25 13:33:54
合計ジャッジ時間 4,737 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
22,096 KB
testcase_01 AC 4 ms
11,680 KB
testcase_02 AC 4 ms
11,384 KB
testcase_03 AC 5 ms
12,672 KB
testcase_04 AC 4 ms
12,840 KB
testcase_05 AC 4 ms
12,744 KB
testcase_06 AC 5 ms
12,836 KB
testcase_07 AC 5 ms
11,360 KB
testcase_08 AC 7 ms
11,452 KB
testcase_09 AC 17 ms
12,724 KB
testcase_10 AC 127 ms
22,408 KB
testcase_11 MLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:39:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |   scanf("%d %d %d", &N, &M, &Q);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |     scanf("%d %d", &A[i], &B[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:47:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |     scanf("%d %d", &C[i], &D[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef pair< int, int > Pi;
 
int data[200000];
vector< int > zig[200000];
int query[200000];
 
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) {
    data[x] += data[y];
    data[y] = x;
    while(!zig[y].empty()) {
      zig[x].push_back(zig[y].back());
      zig[y].pop_back();
    }
  }
}
 
 
int N, M, Q;
bool v[200000];
int A[200000], B[200000];
int C[200000], D[200000];
 
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].push_back(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)].back()] = -1;
    zig[find(0)].pop_back();
  }
   
  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)].back()] = i + 1;
        zig[find(0)].pop_back();
      }
    }
  }
  for(int i = 1; i < N; i++) {
    printf("%d\n", query[i]);
  }
}
0