提出 #47473311
ソースコード 拡げる
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e5+5;
int n,m,fa[N],len[N];
pair<int,int> find(int x)
{
if(x==fa[x])return {x,0};
pair<int,int> ret=find(fa[x]);
int w=ret.second;
fa[x]=ret.first,ret.second+=len[x],len[x]+=w;
return ret;
}
signed main()
{
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++)fa[i]=i;
for(int i=1;i<=m;i++)
{
int x,y,z,a,b;
scanf("%lld%lld%lld",&x,&y,&z);
a=find(x).first,b=find(y).first;
if(a==b)
{
if(a==y&&len[x]!=z)continue;
else if(a==x&&len[y]!=-z)continue;
else if(a!=x&&a!=y&&len[x]-len[y]!=z)continue;
else printf("%lld ",i);
}
else
{
printf("%lld ",i);
fa[a]=b,len[a]=len[y]-len[x]+z;
}
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - Good Set Query |
| ユーザ | lishujia |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 525 |
| コード長 | 750 Byte |
| 結果 | AC |
| 実行時間 | 72 ms |
| メモリ | 7052 KiB |
コンパイルエラー
Main.cpp: In function ‘int main()’:
Main.cpp:16:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | scanf("%lld%lld",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:21:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | scanf("%lld%lld%lld",&x,&y,&z);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 525 / 525 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, example0.txt, example1.txt, example2.txt, hack_001.txt, hack_002.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 28 ms | 3808 KiB |
| 001.txt | AC | 40 ms | 3676 KiB |
| 002.txt | AC | 41 ms | 5292 KiB |
| 003.txt | AC | 27 ms | 5288 KiB |
| 004.txt | AC | 35 ms | 5152 KiB |
| 005.txt | AC | 47 ms | 7032 KiB |
| 006.txt | AC | 48 ms | 7052 KiB |
| 007.txt | AC | 45 ms | 6856 KiB |
| 008.txt | AC | 45 ms | 6916 KiB |
| 009.txt | AC | 48 ms | 3704 KiB |
| 010.txt | AC | 37 ms | 3856 KiB |
| 011.txt | AC | 38 ms | 3732 KiB |
| 012.txt | AC | 38 ms | 3672 KiB |
| 013.txt | AC | 36 ms | 3672 KiB |
| 014.txt | AC | 37 ms | 3676 KiB |
| 015.txt | AC | 45 ms | 3860 KiB |
| 016.txt | AC | 48 ms | 3796 KiB |
| 017.txt | AC | 39 ms | 3812 KiB |
| 018.txt | AC | 39 ms | 3676 KiB |
| 019.txt | AC | 48 ms | 3796 KiB |
| 020.txt | AC | 53 ms | 3804 KiB |
| 021.txt | AC | 42 ms | 3804 KiB |
| 022.txt | AC | 41 ms | 3704 KiB |
| 023.txt | AC | 49 ms | 3828 KiB |
| 024.txt | AC | 55 ms | 3888 KiB |
| 025.txt | AC | 45 ms | 3808 KiB |
| 026.txt | AC | 45 ms | 3988 KiB |
| 027.txt | AC | 54 ms | 4220 KiB |
| 028.txt | AC | 59 ms | 4172 KiB |
| 029.txt | AC | 50 ms | 4036 KiB |
| 030.txt | AC | 72 ms | 6796 KiB |
| 031.txt | AC | 71 ms | 6936 KiB |
| 032.txt | AC | 71 ms | 6796 KiB |
| 033.txt | AC | 66 ms | 6924 KiB |
| example0.txt | AC | 1 ms | 3676 KiB |
| example1.txt | AC | 1 ms | 5304 KiB |
| example2.txt | AC | 1 ms | 3592 KiB |
| hack_001.txt | AC | 1 ms | 3800 KiB |
| hack_002.txt | AC | 1 ms | 3812 KiB |