提出 #38612761


ソースコード 拡げる

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define L0(i,k) for(int i = 0; i <(k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll int64_t
#define vi vector <int>
#define sz(a) ((int) (a).size())
#define all(x) x.begin(),x.end()
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
using namespace std;
const int N = 2e5 + 100;

vector<ll> ad[N];
bool vis[N];
int cc = 0;

int n,m;
void dfs(int s){
	vis[s] = true;
	for(auto x : ad[s]){
		if(!vis[x]){
			cc++;
			dfs(x);
		}
	}
}
void calc(){
     cin>>n>>m;
     for(int i = 0;i<m;i++){
     	int u , v;cin>>u>>v;
     	u--,v--;
     	ad[u].push_back(v);
     	ad[v].push_back(u);
     }
     memset(vis,false,sizeof(vis));
     int k = 0;
     for(int i = 0;i<n;i++){
     	if(!vis[i]){
     		cc = 1;
     		dfs(i);
     		k++;
     	}
     }
     cout<<m - n + k<<"\n";
}
int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0); 
	int t=1;
	//cin >> t;
	while(t--) calc();
	return 0;
}

提出情報

提出日時
問題 C - Don’t be cycle
ユーザ Sagor0078
言語 C++ (GCC 9.2.1)
得点 300
コード長 1071 Byte
結果 AC
実行時間 95 ms
メモリ 20860 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果 AC
AC × 23
セット名 テストケース
Sample
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt
ケース名 結果 実行時間 メモリ
sample00.txt AC 11 ms 8372 KiB
sample01.txt AC 7 ms 8412 KiB
sample02.txt AC 8 ms 8488 KiB
testcase00.txt AC 11 ms 8416 KiB
testcase01.txt AC 41 ms 13700 KiB
testcase02.txt AC 46 ms 14008 KiB
testcase03.txt AC 95 ms 20860 KiB
testcase04.txt AC 88 ms 14952 KiB
testcase05.txt AC 55 ms 12748 KiB
testcase06.txt AC 55 ms 12808 KiB
testcase07.txt AC 81 ms 15840 KiB
testcase08.txt AC 86 ms 15916 KiB
testcase09.txt AC 83 ms 15884 KiB
testcase10.txt AC 83 ms 15916 KiB
testcase11.txt AC 83 ms 15896 KiB
testcase12.txt AC 81 ms 15960 KiB
testcase13.txt AC 82 ms 15876 KiB
testcase14.txt AC 81 ms 15868 KiB
testcase15.txt AC 85 ms 17012 KiB
testcase16.txt AC 87 ms 17092 KiB
testcase17.txt AC 85 ms 17096 KiB
testcase18.txt AC 86 ms 17020 KiB
testcase19.txt AC 85 ms 17068 KiB